DEV Community

Cover image for how to use inline, internal, and external CSS in HTML
Sudhanshu Gaikwad
Sudhanshu Gaikwad

Posted on

1

how to use inline, internal, and external CSS in HTML

1.Inline CSS:
Inline CSS is applied directly to HTML elements using the style attribute.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sudhanshu Developer</title>
</head>
<body>
    <h1 style="color: blue; text-transform: uppercase;">Sudhanshu Developer</h1>
    <p style="font-size: 16px; color: gray;">This is an example of inline CSS.</p>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

2.Internal CSS:
Internal CSS is defined within a tag inside the <head> section of the HTML document.<br> </p> <div class="highlight"><pre class="highlight plaintext"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;title&gt;Sudhanshu Developer&lt;/title&gt; &lt;style&gt; h1 { color: green; text-transform: uppercase; } p { font-size: 18px; color: darkgray; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Sudhanshu Developer&lt;/h1&gt; &lt;p&gt;This is an example of internal CSS.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre></div> <p></p> <p><strong>3.External CSS:</strong><br> External CSS is written in a separate .css file and linked to the HTML document using the <link> tag.<br> First, create a <code>style.css</code> file in your project</p> <p><strong>styles.css:</strong><br> </p> <div class="highlight"><pre class="highlight plaintext"><code>/* styles.css */ h1 { color: red; text-transform: uppercase; } p { font-size: 20px; color: darkblue; } </code></pre></div> <p></p> <p>After That, You create an Index.html File in your project and <br> link the <code>style.css</code> <code>&lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt;</code><br> file in the <code>index.html</code> File.</p> <p><strong>index.html:</strong><br> </p> <div class="highlight"><pre class="highlight plaintext"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;title&gt;Sudhanshu Developer&lt;/title&gt; &lt;link rel="stylesheet" href="styles.css"&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Sudhanshu Developer &lt;/h1&gt; &lt;p&gt;This is an example of external CSS.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre></div> <p></p> <p>In this way, we can use <strong>CSS</strong> in <strong>HTML</strong>.</p>

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay