Typically you embed css that is page specific. Here is how I do my css:

Global css (seperate file(s)):

<link type="text/css" rel="stylesheet" href="css/style.css" media="all" />

NOTE: In today's web world we use a ton of plugins/themes and these plugins/themes tend to roll out newer versions so when you override these plugins/themes make sure you create a css file specific to that theme.

For instance,

Bootstrap 3.1

<link href="/css/bootstrap.3.1.css" rel="stylesheet" type="text/css">

Create this for all your bootstrap overrides so you can use the latest version when it comes out.

<link href="/css/bootstrap.overrides.css" rel="stylesheet" type="text/css">

Page specific css(embedded):

<head>
<!-- last element in head //-->
<style type="text/css">
        .pageSpecific
        {
         color: red;
        }

    </style>
</head>

When I am in development stages or the html element does not require css classification.

Simple style format (inline):

<th style="min-width: 65px;">Column Header</th>

You may have print specific css as well:

  <link href="/css/print.css" rel="stylesheet" type="text/css">

and inside this file wrap your css as such:

@media print{
<!-- print specific css here//-->
}

Keep in mind that you may want to use a css classifcation at a later date when at the time it may seem page specific. Always code for reusability!

Finally:

I like to use css minifier when I put my file(s) into production. I do the same with my javascript files using UglyJs. There is also LESS css that you can use but for now I would stick to these simple conventions or something similar.

Answer from yardpenalty.com on Stack Overflow
🌐
W3Schools
w3schools.com › html › html_css.asp
HTML Styles CSS
HTML Examples HTML Editor HTML ... Messages HTTP Methods PX to EM Converter Keyboard Shortcuts ... CSS stands for Cascading Style Sheets....
🌐
Reddit
reddit.com › r/learnprogramming › adding external css file to html doc
r/learnprogramming on Reddit: Adding external css file to html doc
June 1, 2022 -

I feel stupid and like I have taking 3 steps back in my learning. I am trying to figure out the 3 different implementations of css. Doing External now. Just trying this super simple code, the colors did not show up in the browser like they did on w3schools.

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="styles.css">

</head>

<body>

<h1>This is a heading</h1>

<p>This is a paragraph.</p>

</body>

</html>

Is it because I don't have a css file on my computer? Do I need to download one? Copy and paste from somewhere? I don't get it. I prefer building with the css and html on the same document because I haven't learned how to do anything else yet. I have been able to follow tutorials fine but for some reason, now it's not clicking.

Discussions

Where should css go in .html page? - Stack Overflow
I have a index.html page and a style.css file. I have a style class called .slider and a style class called .logo. Should I put both .slider and .logo inside the style.css page or should i put .sl... More on stackoverflow.com
🌐 stackoverflow.com
html - How can I insert CSS styles inside independent of specific elements? - Stack Overflow
Inline CSS has the drawback that I can't use CSS classes, which is something I need to do. Is there a way to define internal CSS (e.g. a fragment in the element? This would be much easier for me because I could create a self-contained HTML snippet with a method in my ... More on stackoverflow.com
🌐 stackoverflow.com
Where should i add css in html file? - Stack Overflow
I was trying to add css in my blogger's blog but for some reason blogger theme designer is not working so i decided to add css directly in the code using tags, but I can't find the tag in the htm... More on stackoverflow.com
🌐 stackoverflow.com
How to add CSS to HTML code - HTML & CSS - SitePoint Forums | Web Development & Design Community
In the -section of your page, add the following line: b) A CSS-section of your HTML-file You can also add CSS directly in your HTML-file. More on sitepoint.com
🌐 sitepoint.com
0
July 30, 2012
🌐
W3Schools
w3schools.com › css › css_howto.asp
How to add CSS
An external style sheet can be written in any text editor, and must be saved with a .css extension. The external .css file should not contain any HTML tags.
Top answer
1 of 4
3

Typically you embed css that is page specific. Here is how I do my css:

Global css (seperate file(s)):

<link type="text/css" rel="stylesheet" href="css/style.css" media="all" />

NOTE: In today's web world we use a ton of plugins/themes and these plugins/themes tend to roll out newer versions so when you override these plugins/themes make sure you create a css file specific to that theme.

For instance,

Bootstrap 3.1

<link href="/css/bootstrap.3.1.css" rel="stylesheet" type="text/css">

Create this for all your bootstrap overrides so you can use the latest version when it comes out.

<link href="/css/bootstrap.overrides.css" rel="stylesheet" type="text/css">

Page specific css(embedded):

<head>
<!-- last element in head //-->
<style type="text/css">
        .pageSpecific
        {
         color: red;
        }

    </style>
</head>

When I am in development stages or the html element does not require css classification.

Simple style format (inline):

<th style="min-width: 65px;">Column Header</th>

You may have print specific css as well:

  <link href="/css/print.css" rel="stylesheet" type="text/css">

and inside this file wrap your css as such:

@media print{
<!-- print specific css here//-->
}

Keep in mind that you may want to use a css classifcation at a later date when at the time it may seem page specific. Always code for reusability!

Finally:

I like to use css minifier when I put my file(s) into production. I do the same with my javascript files using UglyJs. There is also LESS css that you can use but for now I would stick to these simple conventions or something similar.

2 of 4
2

Styles can go in one of three places.

  1. Inline on the element itself
  2. In the html page
  3. In a separate file

I would suggest either putting it in a <style> tag in the <head> of your html or putting it in a separate file, either will work just as well. Obviously having the styles in a separate file means you could reuse those styles on another page if needed.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Styling_basics › Getting_started
Getting started with CSS - Learn web development | MDN
The very first thing we need to do is to tell the HTML document that we have some CSS rules we want it to use. There are three different ways to apply CSS to an HTML document that you'll commonly come across — external stylesheets, internal stylesheets, and inline styles.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS
CSS: Cascading Style Sheets | MDN
December 29, 2025 - Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in HTML or XML (including XML dialects such as SVG, MathML or XHTML). CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.
Find elsewhere
🌐
W3C
w3.org › Style › Examples › 011 › firstcss.en.html
Starting with HTML + CSS
The menu is already in the HTML page. It is the <ul> list at the top. The links in it don't work, since our “Web site” so far consists of only one page, but that doesn't matter now. On a real Web site, there should not be any broken links, of course. So we need to move the list to the left and move the rest of the text a little to the right, to make room for it. The CSS properties we use for that are 'padding-left' (to move the body text) and 'position', 'left' and 'top' (to move the menu).
Top answer
1 of 5
8

Under the premise, you don't care about invalid HTML in relation of <style> inside <body> (which is not that uncommon), you can assign unique identifier i.e.:

<style>
  .my-class-1 {
    color: gold;
  }
</style>
<div class="my-class-1">Fragment Content</div>

<style>
  .my-class-2 {
    color: tomato;
  }
</style>
<div class="my-class-2">Fragment Content</div>

<div class="my-fragment-1">
  <style>
    .my-fragment-1 .my-class {
      color: teal;
    }
  </style>
  <div class="my-class">Fragment Content</div>
</div>

<div class="my-fragment-2">
  <style>
    .my-fragment-2 .my-class {
      color: hotpink;
    }
  </style>
  <div class="my-class">Fragment Content</div>
</div>

<style id="my-style-1">
  #my-style-1 + div {
    color: orangered;
  }
</style>
<div>Fragment Content</div>

<style id="my-style-2">
  #my-style-2 + div {
    color: indigo;
  }
</style>
<div>Fragment Content</div>

2 of 5
2

the simpler answer to your question is "Yes" and I'll elaborate on this with several examples below. A <style> tag will work wherever you place it within either the <head> or the <body>.

A style tag placed in the <body> tag technically does violate HTML syntax rules, it's surprisingly common in practice, even among some larger corporations.

There are several different methods for including <body>-level <style> tags in your project.

1. Pure HTML <style> tags (the static method)

If you have all the styles you need already written up and there are no dynamic pieces needed, you can simply write those styles into a <style> tag statically and include those in the code, as seen in this example below:

<html>
  <head></head>
  <body>
    <div class="custom-widget">
      <h1>This is a title</h1>
      <p>This is some text.</p>
      <style>
        .custom-widget {
          display: block;
          padding: 20px;
          border: 5px double red;
        }
        .custom-widget h1 {
          text-transform: uppercase;
        }
        .custom-widget h1::first-letter {
          font-size: 150%;
        }
        .custom-widget p {
          font-style: italic;
        }
      </style>
    </div>
  </body>
</html>

2. Writing the styles into a <style> tag as text using JavaScript

If you need to load the styles into your <style> tag dynamically and you simply need plain text styles that you will not need to change much after creating them. You can create the <style> block and then inject the CSS styles as plain text as desired, as seen in this example below:

const counter = document.getElementById('counter');
  let count = +counter.dataset.count;
const customWidgetStyle = document.querySelector('.custom-widget style'),
      countdown = setInterval(() => {
        if (count--) {
          counter.innerText = `Importing CSS in ${count}…`;
        } else {
          clearInterval(countdown);
          counter.remove();
          customWidgetStyle.innerHTML = `
            .custom-widget {
              display: block;
              padding: 20px;
              border: 5px double red;
            }
            .custom-widget h1 {
              text-transform: uppercase;
            }
            .custom-widget h1::first-letter {
              font-size: 150%;
            }
            .custom-widget p {
              font-style: italic;
            }
          `;
        }
      }, 1000);
<html>
  <head></head>
  <body>
    <div class="custom-widget">
      <h1>This is a title</h1>
      <p>This is some text.</p>
      <style></style>
    </div>
    <span id="counter" data-count="3">Importing CSS in 3…</span>
  </body>
</html>

3. Creating cssRules styles into a <style> tag using the JavaScript CSSStyleSheet.insertRule() method

If you need even more flexibility with how you add your styles, you can use the CSSStyleSheet.insertRule() (MDN docs), which will dynamically allow you to add and manage the styles more granularly. This may be overkill for your specific need but there's a lot of power, flexibility, and control when working with the CSSOM.

Here is an example of this method, in which I use an addStylesheetRules function example defined on the MDN docs page for insertRule under the heading Examples, here:

const addStylesheetRules = (rules, stylesheet) => {
  if (stylesheet === undefined) {
    const style = document.createElement('style');
    stylesheet = style.sheet;
    document.head.appendChild(style);
  }
  for (let i = 0; i < rules.length; i++) {
    let j = 1,
        propStr = '';
        rule = rules[i];
    const selector = rule[0];
    if (Array.isArray(rule[1][0])) {
      rule = rule[1];
      j = 0;
    }
    for (let pl = rule.length; j < pl; j++) {
      const prop = rule[j];
      propStr += prop[0] + ': ' + prop[1] + (prop[2] ? ' !important' : '') + ';\n';
    }
    stylesheet.insertRule(selector + '{' + propStr + '}', stylesheet.cssRules.length);
  }
}

const customWidget = document.querySelector('.custom-widget'),
      customWidgetStyleTag = document.createElement('style');
customWidget.appendChild(customWidgetStyleTag);
const customWidgetStylesheet = customWidgetStyleTag.sheet;
addStylesheetRules([
  ['.custom-widget',
    ['display', 'block'],
    ['padding', '20px'],
    ['border', '5px double red']
  ],
  ['.custom-widget h1',
    ['text-transform', 'uppercase']
  ],
  ['.custom-widget h1::first-letter',
    ['font-size', '150%']
  ],
  ['.custom-widget p',
    ['font-style', 'italic']
  ]
], customWidgetStylesheet);
<html>
  <head></head>
  <body>
    <div class="custom-widget">
      <h1>This is a title</h1>
      <p>This is some text.</p>
    </div>
  </body>
</html>


Please let me know if there is any more context I can add to better answer your question.

🌐
Hostinger
hostinger.com › home › tutorials › types of css: inline, external and internal definitions and differences explained
Types of CSS: Inline, Internal and External CSS Explained
April 23, 2025 - Without CSS, your website will appear as a plain HTML page. Here’s how Twitter will look like if we disable its CSS: The main difference between Inline, external and internal CSS Styles is their location and scope of application. Inline CSS styles are included within the HTML document and are specific to individual HTML elements, allowing for targeted styling.
🌐
GeeksforGeeks
geeksforgeeks.org › css › types-of-css-cascading-style-sheet
Types of CSS (Cascading Style Sheet) - GeeksforGeeks
CSS is used to style and layout web pages, controlling the appearance of HTML elements. It allows developers to create visually appealing designs and ensure a consistent look across a website.
Published   July 11, 2025
🌐
Skillstruck
support.skillstruck.com › knowledge › link-a-css-file-to-an-html-file
How to Link a CSS File to an HTML File
July 10, 2025 - CSS is used to style HTML elements on your webpage. While it is possible to include CSS code in an HTML file, it is best practice to write CSS code in its own file and import it to an HTML file. CSS files can be linked to HTML files using the <link> tag. The <link> tag goes between the <head> ...
🌐
Mimo
mimo.org › glossary › css › linking-a-style-sheet
Linking a style sheet in CSS: Learn to Connect CSS to HTML
A stylesheet is a document that contains styling rules for how a web page should look. It controls the visual presentation, including layout, colors, and fonts, of HTML elements. By separating the design (CSS) from the content (HTML), stylesheets make websites easier to manage, update, and ...
🌐
SitePoint
sitepoint.com › html & css
How to add CSS to HTML code - HTML & CSS - SitePoint Forums | Web Development & Design Community
July 30, 2012 - In the <head>-section of your page, add the following line: <link rel=“stylesheet” type=“text/css” href=“style.css” /> b) A CSS-section of your HTML-file You can also add CSS directly in your HTML-file.
🌐
Codecademy
codecademy.com › article › html-inline-styles
Inline Styles in HTML: When to Use | Codecademy
Usually, CSS is written in a separate CSS file (with file extension .css) or in a <style> tag inside of the <head> tag, but there is a third place which is also valid. The third place you can write CSS is inside of an HTML tag, using the style attribute. When CSS is written using the style attribute, it’s called an “inline style”. In general, this is not considered a best practice.
🌐
Team Treehouse
teamtreehouse.com › community › css-doesnt-seem-to-work-on-indexhtml
CSS doesnt seem to work on index.html (Example) | Treehouse Community
September 21, 2022 - If you have your CSS in a separate file, make sure its name is style.css. Inside the <head> tags in your .html file, put <link rel="stylesheet" href="style.css"> This is if both files are in the same folder, if not, then you need to put the file path in front of style.css in the href.
🌐
Quora
quora.com › How-do-I-add-CSS-in-HTML
How to add CSS in HTML - Quora
Answer (1 of 4): There are three ways you can add CSS to an HTML file: 1) Inline styles: You can add CSS styles directly to an HTML element using the style attribute. Here's an example: [code] This is some text [/code]2) Internal styles: You ...
🌐
IONOS
ionos.com › digital guide › websites › web design › linking css to html
How do you link CSS to HTML? Guide with examples
January 5, 2026 - When you include CSS in HTML, it can be done through internal or external stylesheets. Internal stylesheets place the CSS instructions directly in the HTML document. Here, you can integrate CSS at the beginning of the HTML file or continuously ...