0

Linking HTML and CSS

I didn't understand how we link external CSS to html pages. For example in the following code href points to a file insted of a link? What is rel="stylesheet"? Is this a type of link, are there more links, we will link javascript later with this method? <head> <link rel="stylesheet" href="example.css"> </head> <body> <p>This is my first paragraph.</p> <p>This is my second paragraph. </p> <p>This is my third paragraph. </p> </body>

26th Jan 2019, 9:42 PM
Ilie Laurentiu
Ilie Laurentiu - avatar
2 Respostas
+ 2
<link rel="stylesheet" type="text/css" href="example.css"> can you try this?
26th Jan 2019, 10:41 PM
Berkay
Berkay - avatar
+ 1
The href (and src) attribute always contains LINKS to FILES. It can be a link to a local file, or a file on the Internet. Sometimes the link is written in a shortened form, so it won't always look like the big long Internet links that you are used to seeing. The website below shows the different ways of shortening links. https://www.w3schools.com/html/html_filepaths.asp The rel attribute is basically asking, "What is the link for?" So you answer, "It is for a stylesheet!", by typing rel="stylesheet". JavaScript is linked to HTML using a <script> tag and a src attribute instead of href. It needs a closing tag, too. Write it like I have below. It is usually placed just before the close tag of the body, to ensure the HTML elements load before the script. <script src="myCode.js"></script> It is also good practice to include the type attribute, for compatibility with old browsers: type="text/css" for css, or type="text/javascript" for JavaScript.
27th Jan 2019, 12:21 AM
James
James - avatar