Pen Settings



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


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


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.


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, body {
  height: 100%;

body {
  margin: 0;

svg {
  vertical-align: middle;


 * Linear gradients with SVG in JavaScript
 * Published on 28 May 2015
 * Last updated on 6 November 2022

// Store the SVG namespace for easy reuse.
const svgns = '';

 * Create `<svg>,` `<defs>,` `<linearGradient>` and `<rect>` elements, using
 * `createElementNS` to apply the SVG namespace:
const svg = document.createElementNS(svgns, 'svg');
const defs = document.createElementNS(svgns, 'defs');
const gradient = document.createElementNS(svgns, 'linearGradient');
const rect = document.createElementNS(svgns, 'rect');

// Store an array of stop information for the `<linearGradient>`.
const stops = [
    color: "#0C0C7A",
    offset: "0%"
    color: "#5A93FC",
    offset: "100%"

 * Parse the array of stop information and append a `<stop>` element for each
 * stop to `<linearGradient>`.
stops.forEach(stop => {
  const el = document.createElementNS(svgns, 'stop');
  el.setAttribute('offset', stop.offset);
  el.setAttribute('stop-color', stop.color);

  // Add the `<stop>` element to `<linearGradient>`.
 * Apply the `<linearGradient>` to `<defs>`. The `x1`, `x2`, `y1` and `y2`
 * attributes define the staring and ending points, respectively, of the
 * gradient, e.g.:
 * Will create a gradient moving from left to right
 * { x1: 0, x2: 1, y1: 0, y2: 0}
 * Will create a gradient moving from top to bottom
 * { x1: 0, x2: 0, y1: 1, y2: 0}
 * Will create a gradient moving from top left to bottom right.
 * { x1: 0, x2: 1, y1: 0, y2: 1}
 */ = 'Gradient';
gradient.setAttribute('x1', '0');
gradient.setAttribute('x2', '1');
gradient.setAttribute('y1', '0');
gradient.setAttribute('y2', '1');
// Set up the `<rect>` element.
rect.setAttribute('fill', 'url(#Gradient)');
rect.setAttribute('width', '100%');
rect.setAttribute('height', '100%');

// Assign a width and height to the `<svg>` element so that it is visible.
svg.setAttribute('width', '100%');
svg.setAttribute('height', '100%')
// Add the `<defs>` and `<rect>` elements to `<svg>` for the gradient to render.
// Add the `<svg>` element to `<body>`.