Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Advanced CSS Gradient Generator</title>
    <!-- Bootstrap CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background-color: #f8f9fa;
        }
        .gradient-preview {
            height: 300px;
            border: 2px solid #ddd;
            border-radius: 10px;
            margin-bottom: 20px;
            transition: all 0.3s ease-in-out;
            background: linear-gradient(90deg, #ff0000, #0000ff);
        }
        .control-panel {
            background: #ffffff;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        .btn-custom {
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 5px;
            padding: 10px 20px;
            font-size: 16px;
            transition: background-color 0.3s, transform 0.3s;
        }
        .btn-custom:hover {
            background-color: #218838;
            transform: scale(1.05);
        }
        .color-stop-row {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }
        .color-stop-row input[type="color"] {
            flex-grow: 1;
            height: 40px;
            width: 60px;
            border: none;
            margin-right: 10px;
        }
        .color-stop-row .btn-remove {
            color: #dc3545;
            font-size: 18px;
        }
        .range-label {
            display: flex;
            justify-content: space-between;
        }
        pre {
            background: #f1f1f1;
            padding: 15px;
            border-radius: 5px;
            border: 1px solid #ddd;
            font-size: 14px;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
    </style>
</head>
<body>

<div class="container my-5">
    <h1 class="text-center mb-4">Advanced CSS Gradient Generator</h1>
    <div id="gradient-preview" class="gradient-preview"></div>
    <div class="control-panel">
        <div class="mb-3">
            <label for="gradient-type" class="form-label">Gradient Type</label>
            <select id="gradient-type" class="form-select">
                <option value="linear-gradient">Linear</option>
                <option value="radial-gradient">Radial</option>
                <option value="conic-gradient">Conic</option>
            </select>
        </div>
        <div id="color-stops" class="mb-3">
            <div class="color-stop-row">
                <input type="color" value="#ff0000">
                <button class="btn btn-remove"><i class="fas fa-times"></i></button>
            </div>
            <div class="color-stop-row">
                <input type="color" value="#0000ff">
                <button class="btn btn-remove"><i class="fas fa-times"></i></button>
            </div>
        </div>
        <div class="mb-3 text-end">
            <button class="btn btn-custom" id="add-color-stop"><i class="fas fa-plus"></i> Add Color Stop</button>
        </div>
        <div class="mb-3">
            <label for="angle" class="form-label">Angle (Linear Gradient only)</label>
            <input type="range" id="angle" class="form-range" min="0" max="360" value="90">
            <div class="range-label">
                <small>0°</small>
                <small id="angle-value">90°</small>
                <small>360°</small>
            </div>
        </div>
    </div>
    <div class="mt-4">
        <h4>Generated CSS:</h4>
        <pre id="css-code">background: linear-gradient(90deg, #ff0000, #0000ff);</pre>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
<script>
    $(document).ready(function() {
        function updateGradient() {
            const type = $('#gradient-type').val();
            const colors = [];
            $('#color-stops input[type="color"]').each(function() {
                colors.push($(this).val());
            });
            const angle = $('#angle').val();
            const gradient = `${type}(${type === 'linear-gradient' ? angle + 'deg, ' : ''}${colors.join(', ')})`;
            $('#gradient-preview').css('background', gradient);
            $('#css-code').text(`background: ${gradient};`);
        }

        function addColorStop() {
            const newColorStop = `
                <div class="color-stop-row">
                    <input type="color" value="#ffffff">
                    <button class="btn btn-remove"><i class="fas fa-times"></i></button>
                </div>`;
            $('#color-stops').append(newColorStop);
            updateGradient();
        }

        $(document).on('input', 'input[type="color"], #angle', function() {
            updateGradient();
            $('#angle-value').text($('#angle').val() + '°');
        });

        $(document).on('click', '#add-color-stop', addColorStop);
        $(document).on('click', '.btn-remove', function() {
            $(this).closest('.color-stop-row').remove();
            updateGradient();
        });

        updateGradient(); // Initialize preview
    });
</script>

</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console