Link a CSS File to an HTML File

This article describes how to link a CSS file to an HTML file.

Last updated - July 12, 2023

It is important to remember that CSS is used to style HTML. You can either write your CSS code in its own file or include it in line with your HTML. If you have lots of styling to add it is best to use a separate CSS file rather than including it on your HTML file. In order for your CSS styles to apply to your HTML code, you must link your CSS file to your HTML file. This is done by placing a tag similar to this one in the <head> section of your HTML:


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

css

When linking a CSS file to an HTML file, remember:

  • Make sure the link is placed in the head section of your HTML.
  • Include both opening and closing head tags.
  • Make sure the CSS file name is spelled correctly in the link. The CSS file name in the link should match the CSS file exactly.
  • Make sure the syntax used in your link is correct. Check for the correct placement of quotation marks " ", equal signs =  and brackets < >