Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS How to Make a Website CSS: Cascading Style Sheets Use ID Selectors

How do you create a .css file that is to be linked to your .html file on your own?

On Treehouse, they have these files already pre-made, but I am going along also in my own programs and would like to know how you create a .css that is to be linked to your html file.

3 Answers

James Dale
James Dale
3,412 Points

Put something like this in your head tag

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

here is an example

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div>Content.....</div>
</body>
</html>

If you want to include a external CSS file, you would want to add a element to your html page. This element should be placed in the tag and basically relies on three attributes.

The rel for the relationship this link provides, in this case "stylesheet" would be its value. what type of file is being linked, and the location of the file.

To create a CSS file, open a text editor. Save that file as any name you want with .css at the end of it. I recommend you save that file in the same location as your html file, as the href address allows you to add just the name of the CSS file without the absolute URL. Place the name of your CSS file as the href value, and you should be good to go.

hope this helps.

Thank you very much! I should have been more specific and stated that i was talking about making a .css from scratch such as in a text editor so I am thankful that you mentioned this! Thank you! :)