CSS (Cascading Style Sheets) describes how HTML elements should be presented. This section starts with the most basic syntax, then reviews where CSS code can live and when each approach is appropriate.
The Syntax of a Rule
A CSS rule is made up of a selector and a declaration block. The declaration block can contain several property: value declarations, separated by semicolons.
TipInline styles are hard to reuse and maintain, and their high priority can easily override normal style sheets, so they are usually limited to a few dynamically generated cases, such as positioning coordinates computed by JavaScript.
Internal Style Sheets
Written inside a <style> tag in the document's <head>, it applies to the entire HTML file.
It suits small demos and teaching examples on a single page, but the styles cannot be shared across multiple HTML files.
External Style Sheets
CSS lives in a separate .css file and is brought in with a <link> tag. This is the most common and recommended approach in real projects — it separates styles from structure, lets multiple pages reuse the same style sheet, and allows the browser to cache it independently.
Imports one CSS file inside another, often used to split a project into modules (e.g., variables, reset styles).
/* main.css */@importurl("reset.css");
@importurl("variables.css");
body { font-family: var(--font-body); }
Note@import must appear at the very beginning of the style sheet (after @charset), and each @import adds an extra network request and blocks rendering. In production, prefer merging files with a build tool instead of relying on @import.