CSS in the HTML5 page

html and css

It is best to put your CSS in one single place.

This way, the layout will apply not just to a specific location for a specific element of your page (as in the example above), but to all the tags on your page. And if you want to update the presentation, everything is in one place on your page.

To do this, you place your CSS code in the header of your HTML page, inside a <style> tag.

Example:

<html lang="fr">
<head>
<title>HTML5</title>
<meta charset="UTF-8">

<style type="text/css">
   h1 { color: #336699; }
   #txtCenter { text-align: center; }
   #txtSouligne { text-decoration: underline; }
   
   span { font-weight: bold; }
   .txtItalic { font-style : italic; }
   #title { font-size: 32px; }
</style>

</head>

<body>...</body>
</html>

It is therefore possible to write CSS code in the header of an HTML document, inside the <head> tag. As we just saw, you simply need to wrap it in a <style> tag with the attribute type="text/css".

This method allows you to remove the formatting from the body of the document, but it will only apply to the page in question and not to the entire site.

L'élément HTML "style"
L’élément HTML “style” contient des informations de mise en forme pour un document ou une partie d’un document. Par défaut, les instructions de mise en forme écrites dans cet élément sont écrites en CSS.

Here is how you can achieve exactly the same result with a single .html file that contains the CSS code (lines 5 to 10):

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <style>
            p
            {
                color: green;
            }
        </style>
        <title>Premiers tests du CSS</title>
    </head>

    <body>
        <h1>Mon super site</h1>
        
        <p>Bonjour et bienvenue sur mon site !</p>
        <p>Pour le moment, mon site est un peu <em>vide</em>. Patientez encore un peu !</p>
    </body>
</html>

The ideal method in this regard is to use stylesheets in external files and apply them to the document using <link> elements.

If multiple <style> and <link> elements are applied to the document, they will be applied in the order in which they are included in the document. So make sure to check the order to avoid any cascade issues.

Like <link> elements, <style> elements can include media attributes that describe media queries, allowing you to apply stylesheets based on certain criteria from the media being used (such as screen width, for example).

Sudoku Quest

There you go, now you can show off at parties…

Recent Posts

Recent Comments

Itamde is also an online programming school.

Itamde

Learn what you want, at your own pace

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You may also be interested in…

Artificial intelligence is reshaping every pixel

Artificial intelligence is reshaping every pixel

Just a few years ago, editing a photo meant spending hours working meticulously in Photoshop, mastering layers, masks and curves. In 2026, everything has shifted. AI photo editing tools no longer settle for automatic filters — they understand image content, anticipate...

The 10 Best Free AI Tools for Developers in 2026

The 10 Best Free AI Tools for Developers in 2026

Artificial intelligence is transforming how developers write, test, and deploy code. In 2026, many AI tools are freely accessible, offering capabilities that would have seemed impossible just a few years ago. Whether you're a beginner or experienced developer, these...

CSS colors

CSS colors

CSS colors can be defined in hexadecimal. Hexadecimal uses three components: red, green, and blue. You can define colors in shorthand hexadecimal: for example #DC2 corresponds to #DDCC22. Note that some colors cannot be abbreviated. The goal is to shorten your...

Stay up to date with the latest news and developments

Access restricted content

Discover behind-the-scenes details of our projects, exclusive resources, and the progress of our creations in real time.

Sign up for our newsletter

Receive our news, creative insights, and updates from the studio directly in your inbox.

Follow us

Join our community on social media to follow our daily projects and interact with us.