Few simple examples of internal CSS (CSS embedded directly in the HTML document) along with their outputs.

Example 1: Basic Styling with Internal CSS

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Internal CSS Example 1</title>
    <style>
        body {
            background-color: lightblue;
            font-family: Arial, sans-serif;
        }
        
        h1 {
            color: darkblue;
            text-align: center;
        }
        
        p {
            font-size: 16px;
            color: #333;
            line-height: 1.5;
        }
    </style>
</head>
<body>
    <h1>Welcome to My Page</h1>
    <p>This is an example of internal CSS in HTML. The background is light blue, and the text is styled with custom colors and font size.</p>
</body>
</html>

Output:

  • A light blue background on the page.
  • A centered h1 element with dark blue text.
  • A p element with custom font size and color, and proper line spacing.

Example 2: Buttons and Hover Effects

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Internal CSS Example 2</title>
    <style>
        body {
            font-family: 'Courier New', Courier, monospace;
            background-color: #f0f0f0;
            text-align: center;
            margin-top: 50px;
        }

        .btn {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            transition: background-color 0.3s;
        }

        .btn:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <button class="btn">Click Me!</button>
</body>
</html>

Output:

  • A green button that changes color when hovered over.

Example 3: Layout with Flexbox

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Internal CSS Example 3</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }

        .container {
            display: flex;
            justify-content: space-around;
            align-items: center;
            height: 100vh;
        }

        .box {
            width: 100px;
            height: 100px;
            background-color: #3498db;
            border-radius: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            color: white;
            font-size: 18px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="box">Box 1</div>
        <div class="box">Box 2</div>
        <div class="box">Box 3</div>
    </div>
</body>
</html>

Output:

  • Three blue boxes aligned horizontally using Flexbox, with text centered inside each box.

Example 4: Table Styling

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Internal CSS Example 4</title>
    <style>
        table {
            width: 60%;
            margin: 20px auto;
            border-collapse: collapse;
        }

        th, td {
            padding: 10px;
            border: 1px solid #ddd;
            text-align: center;
        }

        th {
            background-color: #4CAF50;
            color: white;
        }

        tr:nth-child(even) {
            background-color: #f2f2f2;
        }

        tr:hover {
            background-color: #ddd;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <th>Name</th>
            <th>Age</th>
            <th>Country</th>
        </tr>
        <tr>
            <td>Alice</td>
            <td>25</td>
            <td>USA</td>
        </tr>
        <tr>
            <td>Bob</td>
            <td>30</td>
            <td>UK</td>
        </tr>
        <tr>
            <td>Charlie</td>
            <td>22</td>
            <td>Canada</td>
        </tr>
    </table>
</body>
</html>

Output:

  • A styled table with alternating row colors, a green header, and a hover effect on rows.

These examples demonstrate different uses of internal CSS to style various HTML elements on a page.