how to link a stylesheet code example

Example 1: how to link css to html

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

Example 2: link stylesheet

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

Example 3: external css link

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

Example 4: link stylesheet in javascript

var cssId = 'myCss';  // you could encode the css path itself to generate id..
if (!document.getElementById(cssId))
{
    var head  = document.getElementsByTagName('head')[0];
    var link  = document.createElement('link');
    link.id   = cssId;
    link.rel  = 'stylesheet';
    link.type = 'text/css';
    link.href = 'http://website.com/css/stylesheet.css';
    link.media = 'all';
    head.appendChild(link);
}

Example 5: how to refer to external style sheet

<html>
<head>
<link rel="stylesheet" type="text/css" href="Name.css">
</head>
<body>
.
.
.
</body>

Tags:

Css Example