-
Hajipur, Bihar, 844101
There are three ways to insert CSS into an HTML document:
CSS is added directly to an HTML element using the style
attribute.
<p style="color: red;">This is a paragraph.</p>
✅ Used for quick, one-off styling.
CSS is written inside a <style>
tag within the <head>
section of the HTML document.
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: blue;
}
</style>
</head>
<body>
<p>This is styled using internal CSS.</p>
</body>
</html>
✅ Used when styling a single HTML page.
CSS is written in a separate .css
file and linked to the HTML using the <link>
tag.
style.css
p {
color: green;
}
index.html
<head>
<link rel="stylesheet" href="style.css">
</head>
✅ Best practice for styling multiple web pages.
CSS files must end with the .css
extension.
Q1. Use inline CSS to make a paragraph's text green.
Q2. Use internal CSS to change all <h1>
text to blue.
Q3. Use external CSS to change the background color of the page to lightgray.
Q4. Write HTML code to link an external CSS file named main.css
.
Q5. Use internal CSS to change all <div>
elements to have 20px padding.
Q6. Write inline CSS to set the font size of a paragraph to 18px.
Q7. Use internal CSS to center-align all <h2>
headings.
Q8. Use external CSS to make all links have no underline.
Q9. Use internal CSS to set a black border around all images.
Q10. Write the HTML and CSS to apply Arial font to all <body>
text using external CSS.
Q1: Which tag is used for internal CSS?
Q2: What is the correct HTML tag to link an external CSS file?
Q3: Where is inline CSS written?
Q4: What is the file extension for CSS files?
Q5: Which CSS method is best for large websites with many pages?
Q6: Which of the following is an example of inline CSS?
Q7: Where is the <link> tag placed in HTML?
Q8: What does external CSS allow?
Q9: Which method overrides all others if used on the same element?
Q10: Which method is not valid in CSS usage?