- Courses
- HTML
- HTML top level tags
- <style>
- Background color from multiple styles
In the following code, what background color will the paragraph have?
<style>
p { background-color: blue; }
</style>
<style>
p { background-color: yellow; }
</style>
<p>This is my paragraph.</p>
The paragraph will have a yellow background.
In the provided code example, there are two <style>
elements with conflicting background-color styles for the paragraph. The second <style>
element specifies a yellow background, which overrides the blue background from the first <style>
element due to its later position in the document. This demonstrates how styles are applied in sequence, with later styles taking precedence if they have the same specificity.
<style>
p { background-color: blue; }
</style>
<style>
p { background-color: yellow; }
</style>
<p>This is my paragraph.</p>