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.
<!--
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
last.fm sounds of the now
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
i learned about the last.fm stuff
from the amazing
Prashant Shrestha (prashant.me)
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
-->
<div id="lastfm">
<div id="covers">
<a id="albumartlink" target="_blank">
<img id="albumart" style="display:none;" alt=" "><!-- the previous line denotes the image showing the artwork associated with the current song -->
</a>
</div>
<div id="sounds">
<h3>Sounds of the Now</h3>
<p>
<span id="current">I've been listening to <a id="tune">
<!-- javascript will fill this area with the song title and artist name -->
</a> lately.</span>
<!-- the previous section (<span id="current"> etc</span>) vanishes entirely if nothing is playing -->
<span id="silent">Nothing is currently playing... maybe you should recommend some music?!</span>
<!--
and is replaced by the previous section (id="silent"), customize as you want -->
Visit the <a href="#">playlists page here</a>, or my <a id="profile" target="_blank">Last.fm profile</a>.
<!-- the previous sentence with the link to a playlists page can be altered in any way you want, to remove the link, add others, etc. Alternatively, remove it entirely. -->
</p>
</div>
</div>
<!-- widget ends here, the script bit below goes just below your </body> tag as usual -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
body {
/* for demonstrative purposes, i've constrained the page to a sidebar-like width of 30%. ignore this part, because usually, you'll be plopping this in your own sidebar or something */
width: 30%;
margin: auto;
}
/*
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
last.fm sounds of the now
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
i learned about the last.fm stuff
from the amazing
Prashant Shrestha (prashant.me)
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
*/
#lastfm {
width: 100%; /* this should remain 100% obviously, if you want it to entirely fill the container in which it is placed, ie, a sidebar, etc... */
margin: 0.5em auto;
border: 0.5em solid; /* border for the entire display container */
border-radius: 0.5em;
background-color: pink; /* the display background color */
transition: 0.3s;
display: inline-block;
}
#covers {
width: 20%;
float: left;
display: block;
}
#lastfm a img#albumart {
width: 100%;
aspect-ratio: auto 1 / 1;
margin: 0.5em;
border: 0.5em solid black; /* border for the album art image, also can function as padding for it if you want to change it to the background color of #lastfm */
border-radius: 0.5em;
}
#sounds {
text-align: center;
float: right;
width: calc(80% - 1.5em);
display: block;
}
/* the next four entries represent wholly aesthetic choices and can be played with and changed as you wish, mostly without breaking the widget :-) */
#sounds h3 {
font-size: 1.5em;
border-bottom: 1em double;
text-align: center;
margin: auto;
font-family: impact;
text-transform: uppercase;
}
#sounds p {
margin: 0 0.5em 0.5em;
text-align: center;
font-size: 0.8em;
font-weight: bold;
padding: 0.4em;
font-family: tahoma;
}
#sounds a {
text-decoration: none;
color: firebrick;
}
#sounds a:hover {
text-decoration: underline;
}
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
// last.fm sounds of the now
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
// i learned about last.fm's stuff
// from the amazing
// Prashant Shrestha (prashant.me)
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
const apikey = "c0fba2a4e49b8d2fa38bfed35df268ab"; //last.fm API key goes here of course...
const username = "ClarityAnne"; //last.fm username goes here...
const s = 60; //number of seconds before each refresh
const profile = "https://last.fm/user/" + username;
const tunes = function () {
$.ajax({
type: "GET",
url:
"https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" +
username +
"&api_key=" +
apikey +
"&format=json&limit=1", //building the call, and calling out to last.fm for your most recent track, but will they grace us with a response? do not refuse the call. it is your destiny, last.fm
dataType: "json",
success: function (resp) {
//oh, they responded - good... moving on...
var tuning = resp.recenttracks.track[0]; //pull most recent track pls?
var formatted = tuning.name + " by " + tuning.artist["#text"]; //format display of most recent track title and artist name
$("#silent").hide(); //hides the error message if there's no error. i love weed...
$("#tune").html(formatted); //adds a line of visible text including the song title and artist
$("#albumart").attr("src", tuning.image[2]["#text"]);
$("#albumart").on("load", function () {
$("#albumart").show();
}); //adds the albumart of the most recent song playe, but only once it has loaded so that there's no "gap" of sorts with a blank image
$("#profile")
.attr("href", profile)
.attr("target", "_blank")
.attr("title", username + " on Last.fm"); //links to your very own last.fm profile automatically!!
$("#tune, #albumartlink") //links both the text displaying the current song and the album art to the song's page
.attr("href", tuning.url)
.attr("title", tuning.name + " by " + tuning.artist["#text"])
.attr("target", "_blank");
},
//this part sets up an error function. it hides the text and the album art portion and shows the notice that nothing is playing. to preview what this looks like, remove your API key or replace it with dummy numbers instead.
error: function (resp) {
$("#covers").hide();
$("#current").hide();
$("#sounds").css("width", "100%");
$("#silent").show();
}
});
};
tunes(); //the function executes when the page loads
setInterval(tunes, s * 1000);
// reloading to see what new stuff is playing. you can remove the latter line (setIntervals etc) if you only want this to load once per page load, without updating.
//i'm so zooted right now
Also see: Tab Triggers