Favorites

Styling Basics - HTML Tutorial

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

So far you've learned how to structure content with HTML: headings, paragraphs, lists, links and images. On their own, though, these elements look fairly plain. Every h1 looks like every other h1.

That's where CSS (Cascading Style Sheets) comes in. You've already used a little CSS to change colors. In this chapter, you'll learn how to write CSS properly, so you can control the look of a whole page, or a whole website, from one place.

By the end of this chapter, you'll be able to:

  • create a style sheet and link it to your pages
  • understand how the browser decides which styles win when rules conflict
  • target specific elements using classes and IDs
  • group content for styling with div and span
  • control fonts, sizes, line spacing and text decoration
  • add borders, padding and margins using the box model
  • align and indent text, and center blocks on the page

Sections in This Chapter

The style Attribute

A closer look at inline styles, and why a better approach is needed for real websites.

Style Sheets

Write CSS rules in a separate file, learn the parts of a rule and understand the cascade, specificity and inheritance.

Classes and IDs

Style specific elements, or groups of elements, using the class and id attributes.

Div and Span

Use the generic div and span containers when no other element fits.

Font Control

Choose fonts and set their size, weight, style and line height, including how to use web fonts.

Borders

Meet the CSS box model, then add borders, rounded corners and outlines.

Margins and Padding

Control the space inside and around elements, and learn the box-sizing setting that makes sizes easier to work with.

Alignment and Indentation

Align and indent text, center blocks and keep lines of text at a comfortable length.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee