Free Ebook cover Complete HTML Course

Complete HTML Course

4.38

(8)

37 pages

CSS styles in HTML

Capítulo 11

Estimated reading time: 2 minutes

+ Exercise
Audio Icon

Listen in audio

0:00 / 0:00

CSS (Cascading Style Sheets) is a style language used to define the appearance and layout of an HTML document. With CSS, you can separate the document's content from its visual presentation, making maintaining and updating your site easier and more efficient.

There are three ways to add CSS styles to an HTML document:

  • Inline styles: are applied directly to an HTML element, using the "style" attribute.
  • Internal styles: are defined within the "head" section of the HTML document, using the "style" tag.
  • External styles: are defined in a separate CSS file and linked to the HTML document via the "link" tag.

Regardless of the form chosen, CSS styles are composed of a selector and a set of properties and values. The selector is used to choose the HTML elements to receive the styles, while the properties and values ​​define the appearance and layout of these elements.

For example, the following CSS code defines a style for all h1 headings in the document:

  
    h1 {
      color: red;
      fontsize: 24px;
      text-align: center;
    }
  

In this case, the selector is "h1" and the properties and values ​​set the text color to red, the font size to 24 pixels, and the text alignment to center.

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

In addition to basic style properties such as color, font, and size, CSS provides a wide variety of properties to control the appearance and layout of HTML elements. Some of the more common properties include:

  • background-color: sets the background color of the element.
  • border: defines the border of the element, including its thickness, style and color.
  • padding: defines the space inside the element, between its content and its border.
  • margin: defines the space outside the element, between its border and the next element.
  • display: defines how the element is displayed on the page, such as block, inline, or flexible.
  • position: defines the element's position on the page, such as static, relative, or absolute.

By combining these properties and values, you can create complex, custom layouts for a website. However, it is important to remember that CSS must be used responsibly and efficiently, avoiding excessive use of styles and ensuring the accessibility and usability of the site for all users.

Now answer the exercise about the content:

_Which of the following is a way to add CSS styles to an HTML document?

You are right! Congratulations, now go to the next page

You missed! Try again.

Among the options given, 'inline styles' is the correct way to add CSS styles to an HTML document. Inline styles involve adding the 'style' attribute directly to an HTML element. The text describes three methods: inline styles, internal styles, and external styles, but 'inline styles' is the only one listed among the options provided in the question.

Next chapter

Introduction to JavaScript in HTML

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.