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.


</script><canvas id="rectangulos" width="300px" height="120px">
 Tu navegador no soporta canvas. <!-- Mensaje para mostrar si el navegador no soporta la etiqueta canvas -->


body {
  background: rgb(29, 31, 32); 
#rectangulos {
  margin: 20px auto;
  display: block;


                var c = document.getElementById("rectangulos");
var cxt = c.getContext("2d");

cxt.fillStyle = "#123456"; // Definimos el color para rellenar el rectangulo
cxt.fillRect(30,10,50,100); // Dibuja un rectangulo relleno - fillRect(x,y,width,height)

cxt.strokeStyle = "red"; // Definimos el color para pintar el borde
cxt.strokeRect(70,32,100,50); // Dibuja el borde del rectangulo - strokeRect(x,y,width,height)

cxt.fillRect(145,25,70,70); // Dibuja un rectangulo relleno del ultimo color definido con fillStyle

cxt.fillStyle = "rgba(220,220,10,0.7)"; // Definimos otro color para rellenar el rectangulo
cxt.fillRect(180,10,100,100); // Dibuja un rectangulo relleno

cxt.clearRect(30,10,20,20); // Borra el contenido que hubiese en el area del rectangulo definido

cxt.strokeRect(190,20,80,80); // Dibuja el borde del rectangulo de definido por ultima vez con strokeStyle.