Appendix A. Essential CSS

It’s no exaggeration to say that modern web design wouldn’t be possible without CSS, the Cascading Style Sheet standard. CSS allows even the most richly formatted, graphically complex web pages to outsource the formatting work to a separate document—a style sheet. This keeps the web page markup clean, clear, and readable.

To get the most out of HTML5 (and this book), you need to be familiar with the CSS standard. If you’re a CSS pro, don’t worry about this appendix—carry on with the material in the rest of the book, and pay special attention to Chapters Chapter 6 and Chapter 7, which introduce many of the new style features that CSS3 adds. But if your CSS skills are a bit rusty, this appendix will help to refresh your memory before you go any further.

Note

This appendix gives a very quick (and not comprehensive) rundown of CSS. If you’re still overwhelmed, consult a book that deals with CSS in more detail, like CSS3: The Missing Manual by David Sawyer McFarland.

Adding Styles to a Web Page

There are three ways to use styles in a web page.

The first approach is to embed style information directly into an element using the style attribute. Here’s an example that changes the color of a heading:

<h1 style="color: green">Inline Styles are Sloppy Styles</h1>

This is convenient, but it clutters the markup terribly. You have to style every line, one by one.

The second approach is to embed an entire style sheet in a <style> element, which you must place ...

Get HTML5: The Missing Manual, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.