HTML CSS Integration: Style, Link and Inline Styles
Style a single element
HTML describes content; CSS describes presentation. A CSS declaration has a property and a value, separated by a colon. The style attribute holds declarations for one element. This small example changes text color without changing the meaning of the paragraph.
The paragraph remains a paragraph and its computed color is navy.
Reuse rules in a stylesheet
A selector identifies matching elements. The rule .note selects elements whose class list includes note. Put reusable rules in a style element in the head of a standalone document; the declarations inside braces apply to each match.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Notes</title> <style>.note { color: navy; }</style> </head> <body> <p class="note">First</p> <p class="note">Second</p> </body></html>Both notes have the same color from one rule.
Link a separate stylesheet
A link with rel="stylesheet" and href loads CSS. In a real project href commonly points to styles.css, resolved against the base URL. Here a data URL supplies a tiny stylesheet without a separate file. Percent-encoded characters represent CSS punctuation.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Linked style</title> <link rel="stylesheet" href="data:text/css,p%7Bcolor%3Ateal%7D"> </head> <body> <p>Linked rule</p> </body></html>The linked CSS sets the paragraph color to teal.
Common mistakes and practice
Do not replace a heading or button with a generic element merely to change its appearance. Prefer a shared stylesheet for reusable project styles. The cascade resolves competing rules; inline styles are not an unconditional override of every rule. A preload is not itself a stylesheet application. Verify computed styles in developer tools.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML CSS Integration: Style, Link and Inline Styles — Knowledge Check
Apply the integration concepts taught in this lesson.
Which attribute holds declarations for one element?
Which link relation applies a CSS file?
What does .note select?
Where should a document-level style element normally go?
Does changing CSS color change a paragraph into a heading?