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="app"></div>
html {
background: #ccc;
font-family: 'Droid Serif', serif;
font-size: 13px;
line-height: 1.3;
}
.content {
overflow: scroll;
resize: both;
padding: 1rem;
width: 260px;
height: 80vh;
background: #CB4338;
color: #fcf3bb;
}
img {
image-rendering: pixelated;
image-rendering: -moz-crisp-edges;
image-rendering: crisp-edges;
width: 100%;
float: left;
margin: 0 1rem 1rem 0;
}
.column-copy {
columns: auto 200px;
column-gap: 2rem;
padding: 1rem 0;
p {
margin: 0 0 1rem 0;
}
}
.controls {
width: 260px;
background: white;
padding: 1rem;
z-index: 1;
position: absolute;
bottom: 1rem;
right: 1rem;
}
.handle {
background: black;
color: white;
text-align: center;
}
h1 {
font-family: 'Playfair Display', serif;
strong {
font-weight: 900;
display: block;
text-transform: uppercase;
}
}
.by {
padding: 0.5rem;
border-top: 2px solid #ec6164;
border-bottom: 2px solid #ec6164;
}
h1 {
font-size: 1.8rem;
margin: 0 0 1rem 0;
strong {
font-size: 3rem;
}
}
label {
display: block;
}
body style {
display: block;
background: #333;
color: white;
white-space: pre;
padding: 10px;
font-family: monospace;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
}
.all-properties {
margin: 0 0 1rem 0;
font-family: monospace;
}
console.clear();
var Draggable = window.ReactDraggable;
class Content extends React.Component {
render() {
return(
<div className="example-content">
<h1><strong>Срочно в номер!</strong> Печатную полосу подстерегает пред­сказанная проблема</h1>
<div className="by">
Кристофер Кривоколессоу
</div>
<p>Переносы строк на странице довольно сложны. Есть ряд CSS-свойств, которые говорят, как переносить строки. Здесь замешаны браузерные префиксы, альтернативные названия свойств, выбор значений и кроссбраузерная поддержка. Возможно, однажды нам станет легче.</p>
<p>Никотинамидадениндинуклеотидфосфатполимераза.</p>
<p>https://fruitcakesandbakingingeneral.foodfoodiefooed.food</p>
<p>Это даже не касается других связаных с этим вещей: <br>, <wbr> и ­.</p>
<p>次の単語グレートブリテンおよび北アイルランド連合王国で本当に大きな言葉</p>
<div className="column-copy">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere quis corrupti minus doloribus sunt perspiciatis sequi quasi ratione voluptas magni, quos dignissimos sint, repellendus id voluptatum ducimus atque eius. Sequi doloribus iusto cupiditate. animi optio nulla nobis, totam quasi repellat ab! Quos excepturi at consequuntur quibusdam eius? Harum, iure!</p>
<img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/paperboy.png' alt='' />
<p>Possimus voluptatum eius ea doloremque iusto minima quasi tempore architecto voluptates, sit inventore libero, illum autem a sequi adipisci quod. Vero et cum nemo aspernatur aliquid temporibus iure reiciendis ratione dicta. Sit, dicta blanditiis quis doloribus beatae id reprehenderit atque aliquid laborum iusto illum praesentium tenetur labore! Incidunt minima nam consectetur officia assumenda dignissimos a vero beatae architecto magni nostrum ratione cum eos, officiis, quis cupiditate! Accusantium dolorem soluta exercitationem enim consequuntur, corrupti quidem voluptatibus odio veniam voluptatum possimus in?</p>
<p>Deleniti vitae voluptatibus incidunt labore vero distinctio odio praesentium dolorem hic quo. Aperiam corporis sint nostrum consequuntur esse. Quidem, quisquam tempora praesentium, ipsam rerum voluptatem ducimus est amet maxime eum minus nulla illo fugit doloribus impedit laudantium inventore distinctio tempore.</p>
</div>
</div>
);
}
}
class PropertyChoices extends React.Component {
constructor(props) {
super(props);
this.state = {
styles: {
'word-break: break-all;': false,
'word-break: break-word;': false,
'word-break: keep-all;': false,
'overflow-wrap: break-word;': false,
'hyphens: manual;': false,
'hyphens: auto;': false,
'line-break: loose;': false,
'line-break: strict;': false,
'line-break: anywhere;': false,
'text-wrap: balance;': false
}
};
}
componentDidUpdate() {
// React hates this.
// StyleFix.styleAttribute(
// document.querySelector("#style")
// );
}
toggleCheckbox(e) {
let property = e.target.parentElement.textContent;
this.setState({
styles: {
...this.state.styles,
[property]: !this.state.styles[property]
}
});
}
render() {
var _this = this;
let allStyles = ``;
Object.keys(this.state.styles).map(function(key) {
if (_this.state.styles[key]) {
if (key === 'hyphens: auto;') {
allStyles += ' -webkit-hyphens: auto;\n -moz-hyphens: auto;\n -ms-hyphens: auto;\n hyphens: auto;\n';
} else if (key === 'hyphens: manual;') {
allStyles += ' -webkit-hyphens: manual;\n -moz-hyphens: manual;\n -ms-hyphens: manual;\n hyphens: manual;\n';
} else if (key === 'overflow-wrap: break-word;') {
allStyles += ' word-wrap: break-word;\n overflow-wrap: break-word;\n';
} else {
allStyles += " " + key + "\n";
}
}
});
return(
<div>
<Draggable handle=".handle">
<form className="controls">
<div className="handle">Тащи меня</div>
<h2>Свойства, связанные с переносами строк</h2>
<div className="all-properties">
{Object.keys(this.state.styles).map(function(key, i) {
return(
<label key={i}>
<input type="checkbox"
checked={_this.state.styles[key]}
onChange={_this.toggleCheckbox.bind(_this)}
/>
{key}
</label>
);
})}
</div>
</form>
</Draggable>
<style id="style" contentEditable dangerouslySetInnerHTML={{
__html:
`body {
${allStyles}}`
}} />
</div>
);
}
}
ReactDOM.render(
<div className="grid">
<div className="choices">
<PropertyChoices />
</div>
<div className="content">
<Content />
</div>
</div>
, document.querySelector("#app"));
Also see: Tab Triggers