HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="rjs_cursor" class="rjs-cursor">
<div class="rjs-cursor-icon"></div>
</div>
<div class="page-content">
<h1>Custom cursor with CSS</h1>
<p>
<a href="https://ralphjsmit.com/animated-custom-cursor" rel="noopener">Read the article</a>
</p>
<p>
<!-- start slipsum code -->
Well, the way they make shows is, they make one show. That show's called a pilot. Then they show that show to the people who make shows, and on the strength of that one show they decide if they're going to make more shows. <a href="https://ralphjsmit.com/>">Some pilots</a> get picked and become television programs. Some don't, become nothing. She starred in one of the ones that became nothing.
<!-- end slipsum code -->
</p>
<form action="#form">
<p>
<label for="text">Dummy form</label><br>
<input type="text" id="text">
</p>
<button>Send</button>
</form>
<br>
<div class="mycustomclass" style="display: inline-block; height: 40px; background-color: orange; padding: 6px; line-height: 40px; color: white; margin: 6px; border-radius: 8px;">Custom clickable div</div>
</div>
.rjs-cursor {
width: 12px;
height: 12px;
position: fixed; /* Fixed position.. */
top: 0; /* at the top left.. */
left: 0;
z-index: 999999; /* above everything else. */
pointer-events: none; /* Cant't be clicked. */
transition: none; /* Cursor is always accurate */
opacity: 0; /* Hidden by default */
transform: translate(-50%; -50%);
}
.rjs-cursor-icon { /* Styling for the visible part */
width: 100%;
height: 100%;
border-radius: 100%; /* Circle */
background-color: #ffe3d3; /* Backup value */
transition: all 0.2s ease;
transform-origin: 50% 50%;
}
.rjs-cursor.rjs_cursor_visible { opacity: 1; }
.rjs-cursor.rjs_cursor_hidden { opacity: 0; }
/* Display the cursors at the correct time */
* { cursor: none; }
@media (pointer: none), (pointer: coarse) {
#rjs_cursor, #rjs_cursor .rjs-cursor-icon { display: none !important; visibility: hidden; opacity: 0; }
* { cursor: auto !important; }
}
/* Hover effects */
.rjs-cursor.rjs_cursor_hover .rjs-cursor-icon { transform: scale(2); }
/* The body element is required to fill the complete browser. This will be the case on almost every website that has content. Otherwise you could add this as a fallback */
body { min-width: 100vw; min-height: 100vh; margin: 0; } */
var rjs_cursor = document.getElementById("rjs_cursor"); //Getting the cursor
var body = document.querySelector("body"); //Get the body element
//Functions for showing and hiding the cursor
//They are referenced the
function rjs_show_cursor(e) { //Function to show/hide the cursor
if(rjs_cursor.classList.contains('rjs_cursor_hidden')) {
rjs_cursor.classList.remove('rjs_cursor_hidden');
}
rjs_cursor.classList.add('rjs_cursor_visible');
}
function rjs_hide_cursor(e) { if(rjs_cursor.classList.contains('rjs_cursor_visible')) {
rjs_cursor.classList.remove('rjs_cursor_visible');
}
rjs_cursor.classList.add('rjs_cursor_hidden');
}
function rjs_mousemove(e) { //Function to correctly position the cursor
rjs_show_cursor(); //Toggle show/hide
var rjs_cursor_width = rjs_cursor.offsetWidth * 0.5;
var rjs_cursor_height = rjs_cursor.offsetHeight * 0.5;
var rjs_cursor_x = e.clientX - rjs_cursor_width; //x-coordinate
var rjs_cursor_y = e.clientY - rjs_cursor_height; //y-coordinate
var rjs_cursor_pos = `translate(${rjs_cursor_x}px, ${rjs_cursor_y}px)`;
rjs_cursor.style.transform = rjs_cursor_pos;
}
//Eventlisteners
window.addEventListener('mousemove', rjs_mousemove); //Attach an event listener
body.addEventListener('mouseleave', rjs_hide_cursor);
//Hover behaviour
function rjs_hover_cursor(e) { rjs_cursor.classList.add('rjs_cursor_hover'); }
function rjs_unhover_cursor(e) { rjs_cursor.classList.remove('rjs_cursor_hover'); }
document.querySelectorAll('a').forEach(item => {
item.addEventListener('mouseover', rjs_hover_cursor);
item.addEventListener('mouseleave', rjs_unhover_cursor);
})
document.querySelectorAll('input').forEach(item => { //Input tags
item.addEventListener('mouseover', rjs_hover_cursor);
item.addEventListener('mouseleave', rjs_unhover_cursor);
})
document.querySelectorAll('button').forEach(item => { //Input tags
item.addEventListener('mouseover', rjs_hover_cursor);
item.addEventListener('mouseleave', rjs_unhover_cursor);
})
document.querySelectorAll('.mycustomclass').forEach(item => { //A custom class
item.addEventListener('mouseover', rjs_hover_cursor);
item.addEventListener('mouseleave', rjs_unhover_cursor);
})
Also see: Tab Triggers