Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Connecting HTML and CSS | Introduction to CSS
CSS Fundamentals

book
Connecting HTML and CSS

Unveiling the Three Paths

When it comes to designing a website, the visual appearance of a webpage is primarily influenced by two technologies - HTML and CSS. These two technologies work together in three distinct ways: inline styles, embedded style sheets, and external style sheets. Let's unravel the artistry behind these methods, exploring their strengths and weaknesses.

Inline Styles

Inline styles introduce CSS directly to an HTML element using the style attribute. These styles are convenient when dynamic changes are needed – a realm where JavaScript often wields its magic. However, the drawback is their limited scope; they can't be easily extended or reused across different elements.

<tag style="...">Some content</tag>

For example, let's apply an inline style to change the text color to blueviolet.

html

index.html

copy
<p style="color: blueviolet">Let's use inline styles and check the result</p>

Embedded Style Sheet

The embedded style sheet resides within an HTML document's <head>, encapsulated within <style> tags. This method allows us to tailor styles specifically to a single page. However, it lacks the versatility needed to be shared across multiple pages.

html

index.html

copy
<!DOCTYPE html>
<html lang="en">
<head>
<style>
p {
color: blueviolet;
font-size: 36px;
}
</style>
</head>
<body>
<p>We work with an embedded style sheet in the head of HTML.</p>
</body>
</html>

External Style Sheet

The external style sheet emerges as the grand maestro of CSS management. By employing the <link> tag within the <head> of an HTML document, this technique offers scalability, maintainability, and reusability – qualities coveted in web projects.

But how does it work? We create a file with the css extension and reference it in our HTML document. Below is a glimpse of both files, index.html and index.css.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<!-- We can add multiple links to CSS style sheets if needed. -->
<link rel="stylesheet" href="index.css" />
</head>
<body>
<p>We work with an external style sheet connected in the head.</p>
</body>
</html>

The rel attribute stands for "relationship". rel="stylesheet" denotes how the index.css is related to the index.html.

Note

Remember that while inline styles cater to a single element, styles from an External Style Sheet or an Embedded Style Sheet can adorn multiple elements, streamlining your design efforts.

What ways of adding styles to the HTML document exist?

What ways of adding styles to the HTML document exist?

Selecciona unas respuestas correctas

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 2
some-alt