CSS inline
Created By: chatGPT
Inline CSS is used to apply styles directly to an HTML element using the style attribute. This method is ideal for quick styles that won’t be reused elsewhere in the document. However, it’s not the best practice for larger projects because it mixes content with presentation. Here’s how you can create a simple box with a background color and padding using inline CSS.
<div style="background-color: lightblue; padding: 20px;">
<h1 style="color: navy;">Welcome to Inline CSS!</h1>
<p style="font-size: 16px;">This is a paragraph styled directly in the HTML.</p>
</div>
In the example above, we created a
div
with a light blue background and 20 pixels of padding. Inside the div
, we have an h1
and a p
element, each with their own inline styles. This approach makes the styles clear to see because they are right next to the elements they apply to.<div style="border: 2px solid black;">
<p style="color: green; font-weight: bold; text-align: center;">This paragraph has a green color, bold text, and is centered.</p>
</div>
While inline CSS is convenient for small changes or specific items, it's recommended to use internal or external stylesheets for larger projects as they offer better maintainability and separation of concerns. However, understanding inline CSS is essential for quick demonstrations or testing.
<button style="background-color: red; color: white; border: none; padding: 10px;">Click Me!</button>