A CSS file is a plain text document that holds all the styling rules for your website

You create a CSS file the same way you create any text file: open a text editor, write your code, and save it with the .css extension. The file itself is just plain text — no special software needed. What matters is the extension at the end of the filename and where you save it in relation to your HTML files.

The reason you use a separate CSS file instead of writing styles directly in your HTML is that one CSS file can style multiple pages. If you change a color or font in that one file, the change appears everywhere that file is linked. This saves you from editing the same style rule in dozens of HTML files.

Key Takeaways

  • Save your CSS as a plain text file with the .css extension, using any text editor including Notepad, VS Code, or Sublime Text.
  • Link your CSS file to your HTML using a tag in the section, with the href pointing to where you saved the CSS file.
  • Keep your CSS file in the same folder as your HTML files, or in a subfolder like /css, to make the file path simple and portable.
  • The filename itself can be anything — styles.css, main.css, or theme.css all work — but the .css extension is required for browsers to recognize it as a stylesheet.

Creating a CSS file in a text editor

Open any text editor on your computer. On Windows, Notepad works fine. On Mac, use TextEdit (but switch it to plain text mode first — go to Format menu and select Make Plain Text). If you already use VS Code, Sublime Text, or another code editor, open that instead.

Type or paste your CSS rules into the editor. A simple example:

body {   background-color: lightblue;   font-family: Arial, sans-serif; } h1 {   color: navy;   text-align: center; }

Once your CSS is written, go to File and select Save As. Choose where you want to save the file — ideally in the same folder as your HTML files, or in a subfolder called css. Type the filename with the .css extension at the end. For example: styles.css or main.css. Click Save.

Linking your CSS file to your HTML

Creating the CSS file is only half the work. Your HTML file needs to know where to find it. Open your HTML file in your text editor and locate the <head> section — this is where links to external files go.

Inside the <head>, add a link tag that points to your CSS file:

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

If your CSS file is in a subfolder called css, the href changes to point to that path:

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

The href attribute tells the browser where to find the file. It can be a relative path (relative to where your HTML file sits) or an absolute path (the full web address if the CSS is hosted elsewhere). For files on your own computer, use a relative path.

File paths and folder organization

The most common setup is to keep your CSS file in the same folder as your HTML file. If your HTML file is called index.html and your CSS file is called styles.css, and they are in the same folder, the link tag is simply:

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

If you create a subfolder to organize your files better, the path changes. A typical structure looks like this:

Folder structureLink tag in HTML
index.html and styles.css in the same folder<link rel="stylesheet" href="styles.css">
index.html in root folder, styles.css in a css subfolder<link rel="stylesheet" href="css/styles.css">
index.html in a pages subfolder, styles.css in a css subfolder at the root<link rel="stylesheet" href="../css/styles.css">

The ../ means "go up one folder level." This matters when your HTML and CSS are not in the same folder. Test your link by opening the HTML file in a browser — if the styles do not appear, the file path is wrong.

Choosing the right text editor

Notepad or TextEdit work, but a code editor makes the job easier. VS Code is free and widely used. It highlights your CSS syntax in different colors so you spot mistakes faster, and it shows you hints as you type. Sublime Text and Atom are other popular choices, all free or low-cost.

The editor you choose does not change how the CSS file works — it just changes how comfortable you are writing it. If you are starting out, VS Code is a solid choice because it handles HTML, CSS, and JavaScript all in one place, and the learning curve is gentle.

Saving and naming conventions

The filename can be anything as long as it ends in .css. Common names are styles.css, main.css, theme.css, or app.css. Pick a name that tells you what the file does. If you have multiple CSS files for different parts of your site, name them accordingly — header.css, footer.css, responsive.css.

Always use lowercase letters and no spaces in the filename. Instead of "my styles.css", use "my-styles.css" or "mystyles.css". Spaces and uppercase letters can cause problems on some web servers, especially when you move your site from your computer to the internet.

Save the file in UTF-8 encoding, which is the standard for web files. Most modern editors default to UTF-8, but if you are using Notepad, check the encoding dropdown when you save.

Testing that your CSS file is linked correctly

Open your HTML file in a web browser. If the styles appear — the colors, fonts, spacing, and layout all show up — your link is working. If the page looks plain and unstyled, the browser could not find the CSS file.

Check three things: First, verify the filename in your href matches the actual filename exactly, including capitalization. Second, make sure the file path is correct — if your CSS is in a subfolder, the href must include that subfolder. Third, confirm the CSS file is actually saved with the .css extension, not as .txt or something else.

In most browsers, you can right-click the page, select Inspect or Inspect Element, and look at the Network tab to see if the CSS file loaded. If it shows a 404 error, the file path is wrong.

Frequently Asked Questions

Can I use Notepad to create a CSS file?

Yes. Open Notepad, write your CSS, go to File > Save As, and save it with the .css extension. Make sure the file type dropdown says "All Files" so Notepad does not add .txt to the end. On Mac, use TextEdit but switch to plain text mode first under the Format menu.

What if my CSS file is not working even though the link is correct?

Check that your CSS syntax is valid — missing semicolons or curly braces will break the whole file. Open your browser's developer tools (right-click, Inspect), go to the Console tab, and look for error messages. Also confirm the file was saved with the .css extension, not as plain text.

Can I have multiple CSS files linked to one HTML file?

Yes. Add multiple link tags in the head section, one for each CSS file. The order matters — if two files style the same element, the one listed last wins. This is useful when you want to keep different styles organized in separate files.

Do I need to upload my CSS file separately when I put my site online?

Yes. When you move your HTML and CSS files to a web server, you must upload both. The folder structure should match your local setup — if your CSS is in a css subfolder on your computer, create that same subfolder on the server and upload the CSS file there.

What is the difference between a CSS file and writing styles in the HTML head?

Writing styles in the HTML head (using a style tag) works for one page only. A separate CSS file can be linked to many HTML pages, so you change the style once and it updates everywhere. For anything beyond a single test page, a separate CSS file is the better approach.