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.
<h1>Validation de formulaire sans JavaScript</h1>
<p>Pour ne pas écrire une ligne de JavaScript afin de valider vos formulaires, il vous faudra 3 scripts.</p>
<ul>
<li><a href="https://jquery.com/">jQuery</a> (//code.jquery.com/jquery-2.1.4.min.js)</li>
<li><a href="https://jqueryvalidation.org/">jQuery Validation Plugin</a> (//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.min.js)</li>
<li><a href="https://www.nuget.org/packages/jQuery.Validation.Unobtrusive/">jQuery Validation Unobstrusive Plugin</a> (//ajax.aspnetcdn.com/ajax/mvc/5.2.3/jquery.validate.unobtrusive.min.js)</li>
</ul>
<h2>Formulaire standard</h2>
<form action="">
<fieldset>
<legend>Champs simple</legend>
<label for="pseudo">Pseudo</label>
<input
type="text"
name="pseudo"
placeholder="Haeresis"
data-rule-required="true"
data-msg-required="Le champ Pseudo est requis."
/>
<span data-valmsg-for="pseudo" data-valmsg-replace="true"></span>
</fieldset>
<fieldset>
<legend>Champs email</legend>
<label for="email">Email</label>
<input
type="text"
name="email"
placeholder="bruno.lesieur@gmail.com"
data-rule-required="true"
data-msg-required="Le champ Email est requis."
data-rule-email="true"
data-msg-email="Le champ Email n'a pas le bon format."
/>
<span data-valmsg-for="email" data-valmsg-replace="true"></span>
</fieldset>
<fieldset>
<legend>Champs mot de passe</legend>
<div>
<label for="password">Mot de passe</label>
<input
type="password"
name="password"
placeholder="Mot de passe"
data-rule-required="true"
data-msg-required="Le champ Password est requis."
data-val="true"
data-val-regex-pattern="^(?=.*[A-Za-z])(?=.*\d).{6,}$"
data-val-regex="Le champ Password doit faire au minimum 6 caractères, et inclure une lettre et un nombre."
/>
<span data-valmsg-for="password" data-valmsg-replace="true"></span>
</div>
<div>
<label for="confirm">Confirmation</label>
<input
type="password"
name="confirm"
placeholder="Confirmer le mot de passe"
data-val="true"
data-val-equalto="Le mot de passe de confirmation ne correspond pas au mot de passe."
data-val-equalto-other="password"
/>
<span data-valmsg-for="confirm" data-valmsg-replace="true"></span>
</div>
</fieldset>
<fieldset>
<legend>Champs de choix</legend>
<div>
<label for="gender">Sexe</label>
<input
type="radio"
name="gender"
id="male"
value="choice-1"
data-rule-required="true"
data-msg-required="Le choix Sexe est requis."
/>
<label for="male">Homme</label>
<input type="radio" name="gender" id="female" value="choice-2" />
<label for="female">Femme</label>
<span data-valmsg-for="gender" data-valmsg-replace="true"></span>
</div>
</fieldset>
<fieldset>
<legend>Champs de sélection</legend>
<div>
<label for="relationship">Situation</label>
<select
name="relationship"
data-rule-required="true"
data-msg-required="La sélection Situation est requise."
>
<option value="">Sélectionner</option>
<option value="avenue">Célibataire</option>
<option value="chemin">En couple</option>
<option value="rue">Marié</option>
</select>
<span data-valmsg-for="relationship" data-valmsg-replace="true"></span>
</div>
</fieldset>
<fieldset>
<legend>Champs texte</legend>
<label for="description">Description</label>
<div>
<textarea
cols="40"
rows="8"
name="description"
data-rule-required="true"
data-msg-required="Le texte Description est requis."
data-rule-minlength="10"
data-msg-minlength="Le texte Description doit faire au minimum 10 caractères."
data-rule-maxlength="100"
data-msg-maxlength="Le texte Description doit faire au maximum 100 caractères."
></textarea>
</div>
<span data-valmsg-for="description" data-valmsg-replace="true"></span>
</fieldset>
<fieldset>
<legend>Champs case</legend>
<div>
<input
type="checkbox"
name="terms"
id="terms"
data-rule-required="true"
data-msg-required="La case Accepter les termes et conditions est requise."
/>
<label for="terms">Accepter les termes et conditions</label>
<span data-valmsg-for="terms" data-valmsg-replace="true"></span>
</div>
</fieldset>
<fieldset>
<legend>Champs date</legend>
<label for="birthdate">Anniversaire</label>
<input
type="text"
name="birthdate"
placeholder="dd/mm/yyyy"
data-rule-required="true"
data-msg-required="Le champ Anniversaire est requis."
data-val="true"
data-val-regex="Une date valide est au format dd/mm/yyyy"
data-val-regex-pattern="^([0-9]{2})/([0-9]{2})/([0-9]{4})$"
data-val-regex-flags="g"
/>
<span data-valmsg-for="birthdate" data-valmsg-replace="true"></span>
</fieldset>
<fieldset>
<legend>Champs nombre</legend>
<label for="age">Age</label>
<input
type="text"
name="age"
placeholder="Nombre d'année"
data-rule-required="true"
data-msg-required="Le champ Age est requis."
data-val="true"
data-val-regex="Entrez un nombre entre 1 et 2 chiffres"
data-val-regex-pattern="\d{1,2}"
data-val-range="Un age authorisé est de 7 à 77 ans"
data-val-range-max="77" data-val-range-min="7"
/>
<span data-valmsg-for="age" data-valmsg-replace="true"></span>
</fieldset>
<fieldset>
<legend>Champs url</legend>
<label for="website">Site</label>
<input
type="text"
name="website"
placeholder="http://www.exemple.com/"
data-rule-required="true"
data-msg-required="Le champ Site est requis."
data-rule-url="true"
data-msg-url="Le champ Site n'a pas le bon format."
/>
<span data-valmsg-for="website" data-valmsg-replace="true"></span>
</fieldset>
<fieldset>
<legend>Champs caché</legend>
<div>
<label for="hidden">Caché avec type hidden</label>
<input
type="hidden"
name="hidden"
data-rule-required="true"
data-msg-required="Le champs Caché avec type hidden est requis."
/>
<span data-valmsg-for="hidden" data-valmsg-replace="true"></span>
</div>
<div>
<label for="hidden-css">Caché en CSS</label>
<input
class="hidden"
type="text"
name="hidden-css"
data-rule-required="true"
data-msg-required="Le champs Caché en CSS ! est requis."
/>
<span data-valmsg-for="hidden-css" data-valmsg-replace="true"></span>
</div>
</fieldset>
<fieldset>
<legend>Champs asynchrone</legend>
<div class="asynchone-field">
Un champ va arriver de manière asynchrone.
</div>
</fieldset>
<hr />
<div class="validation-summary-valid" data-valmsg-summary="true">
<ul>
<li style="display:none"></li>
</ul>
</div>
<div>
<input id="visible" type="submit" value="Valider les champs visible" />
</div>
<hr />
<div>
<input id="all" type="submit" value="Valider tous les champs" />
</div>
<hr />
<div>
<input id="ignore" type="submit" value="Valider tous les champs, sauf ceux inclu dans « .hidden »" />
</div>
</form>
<hr />
<h2>Formulaire asynchrone</h2>
<div class="asynchone-form">
Un formulaire va arriver de manière asynchrone.
</div>
/* Les messages d'erreur en rouge */
.validation-summary-errors,
.field-validation-error {
color: #f00;
}
.input-validation-error {
border: 1px solid #f00;
}
/* Cacher des champs */
.hidden {
display: none;
}
/* Champs désactivé */
[disabled] {
opacity: 0.5;
}
/* Style pour embeded page */
html {
font-size: 62.5%;
}
body {
margin: 0 0 2px;
padding: 8px;
border: 1px dashed #ccc;
font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
font-size: 1.4rem;
line-height: 21px;
color: #777;
font-weight: 300;
padding: 8px;
}
h1 {
color: #222;
margin: 32px 0 0;
font-weight: 400;
line-height: 1;
}
/*****************************************\
Valider tous les champs visible en
n'ajoutant rien ou
en ajoutant la ligne JavaScript
« $.validator.setDefaults({ ignore: ":hidden" }); »
\*****************************************/
$("#visible").click(function (event) {
event.preventDefault();
$("#ignore").attr("disabled", true).after($("<span>").text(" Recharger la page pour tester les autres boutons (RERUN bouton)."));
$("#all").attr("disabled", true).after($("<span>").text(" Rechargé la page pour tester les autres boutons (RERUN bouton)."));
$(this).parents('form').validate().settings.ignore = ":hidden";
$(this).parents('form').submit();
});
/*****************************************\
Valider les champs invisible
en ajoutant la ligne JavaScript
« $.validator.setDefaults({ ignore: [] }); »
\*****************************************/
$("#all").click(function (event) {
event.preventDefault();
$("#visible").attr("disabled", true).after($("<span>").text(" Recharger la page pour tester les autres boutons (RERUN bouton)."));
$("#ignore").attr("disabled", true).after($("<span>").text(" Recharger la page pour tester les autres boutons (RERUN bouton)."));
$(this).parents('form').validate().settings.ignore = [];
$(this).parents('form').submit();
});
/*****************************************\
Valider tous les champs sauf ceux « .hidden »
en ajoutant la ligne JavaScript
« $.validator.setDefaults({ ignore: ".hidden" }); »
\*****************************************/
$("#ignore").click(function (event) {
event.preventDefault();
$("#visible").attr("disabled", true).after($("<span>").text(" Recharger la page pour tester les autres boutons (RERUN bouton)."));
$("#all").attr("disabled", true).after($("<span>").text(" Rechargé la page pour tester les autres boutons (RERUN bouton)."));
$(this).parents('form').validate().settings.ignore = ".hidden";
$(this).parents('form').submit();
});
/*****************************************\
Des nouveaux champs peuvent être ajouté à
la volée.
\*****************************************/
$(function () {
setTimeout(function () {
$(".asynchone-field").html('<label for="async-field">Asynchrone</label> <input type="text" name="async-field" data-rule-required="true" data-msg-required="Le champs Asynchrone est requis."/> <span data-valmsg-for="async-field" data-valmsg-replace="true"></span> (Ce champ est arrivé après le chargement de la page)');
}, 10000);
});
/*****************************************\
Pour forcer la validation d'un formulaire
arriver dans le DOM après, utiliser.
« $.validator.unobtrusive.parse('form'); »
\*****************************************/
$(function () {
setTimeout(function () {
$(".asynchone-form").html('<form action="" method="post"><label for="async">Asynchrone</label> <input type="text" name="async" data-val="true" data-rule-required="true" data-msg-required="Valider un formulaire asynchrone"/> <span data-valmsg-for="async" data-valmsg-replace="true"></span> <input type="submit" value="Test Asynchrone" /> (Ce formulaire est arrivé après le chargement de la page)<div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li></ul></div></form>');
$.validator.unobtrusive.parse('form');
}, 10000);
});
Also see: Tab Triggers