### Example activated virtual environment prompt
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/django/development_environment/index.md
After activation, the start of your prompt shows the environment name in parentheses. This example shows the prompt on Ubuntu; the effect is the same on Windows/macOS.
```plain
(my_django_environment) ubuntu@ubuntu:~$
```
--------------------------------
### Check language pack availability and install with SpeechRecognition.available() and install()
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/speechrecognition/install_static/index.md
Use this to check whether an on-device language pack is available and install it if needed. If processLocally is true and the pack is missing, start() fails with a service-not-allowed error. The install() promise resolves true on success or false on failure.
```javascript
startBtn.addEventListener("click", () => {
// Check availability of target language
SpeechRecognition.available({ langs: ["en-US"], processLocally: true }).then(
(result) => {
if (result === "unavailable") {
diagnostic.textContent = `en-US not available to download at this time. Sorry!`;
} else if (result === "available") {
recognition.start();
console.log("Ready to receive a color command.");
} else {
diagnostic.textContent = `en-US language pack downloading`;
SpeechRecognition.install({
langs: ["en-US"],
processLocally: true,
}).then((result) => {
if (result) {
diagnostic.textContent = `en-US language pack downloaded. Try again.`;
} else {
diagnostic.textContent = `en-US language pack failed to download. Try again later.`;
}
});
}
},
);
});
```
--------------------------------
### Start http-server with npx
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/howto/tools_and_setup/set_up_a_local_testing_server/index.md
Run this command in the directory containing your example to host files on localhost:9999. The -o flag opens the browser, and -c-1 disables caching.
```bash
npx http-server -o -p 9999 -c-1
```
--------------------------------
### HTML and CSS setup for interactive font-style example
Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/reference/properties/font-style/index.md
Provides the markup and font-face declaration used to demonstrate variable font styling.
```html
London. Michaelmas term lately over, and the Lord Chancellor sitting in
Lincoln's Inn Hall. Implacable November weather. As much mud in the streets
as if the waters had but newly retired from the face of the earth, and it
would not be wonderful to meet a Megalosaurus, forty feet long or so,
waddling like an elephantine lizard up Holborn Hill.
```
```css
@font-face {
src: url("/shared-assets/fonts/variable-fonts/AmstelvarAlpha-VF.woff2");
font-family: "Amstelvar";
font-style: normal;
}
section {
font-size: 1.2em;
font-family: "Amstelvar", serif;
}
```
--------------------------------
### Import a module for its side effects only
Source: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/guide/modules/index.md
Use an import with only a module specifier to run a module's initialization code without importing any exports, for example to install a polyfill.
```javascript
import "./modules/polyfills.js";
```
--------------------------------
### Set up index.html and style.css starter files
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/core/text_styling/typesetting_a_homepage/index.md
Create index.html and style.css in the typesetting-challenge directory to initialize the starting layout and content. Link style.css inside index.html and pair them with the external link icon asset before testing in a browser.
```html
St Huxley's Community College
St Huxley's Community College
Brave new world
It's a brave new world out there. Our children are being put in
increasingly more competitive situations as they move through the
different stages of their life with
examinations, jobs,
careers, and
other life choices. Having the wrong mindset or making the wrong
choices can lead to problems at all stages.
As concerned parents, guardians, or carers, you will no doubt want
to give your children the best possible start in life — and you've
come to the right place.
The best start in life
At St. Huxley's, we pride ourselves in not only giving our students
a top-quality education, but also giving them the
societal and
emotional
intelligence they need to win big in the future. We not only excel
at subjects such as genetics, data mining, and chemistry, but we
also include compulsory lessons in:
Emotional resilience
Critical thinking
Judgment
Assertion
Focus and resolve
If you are interested, then don't hesitate to get in touch; we'd
love to hear from you:
```
```css
/* General setup */
* {
box-sizing: border-box;
}
body {
margin: 0 auto;
padding: 0 20px;
min-width: 980px;
max-width: 1400px;
}
/* Layout */
main {
display: grid;
grid-template-columns: 5fr 2fr 2fr;
gap: 40px;
padding: 20px 0;
}
/* header and footer */
header {
border-bottom: 5px solid #aa6666;
}
footer {
border-top: 5px solid #aa6666;
}
footer p {
text-align: center;
}
```
--------------------------------
### Hidden JavaScript game code
Source: https://github.com/mdn/content/blob/main/files/en-us/games/tutorials/2d_breakout_game_pure_javascript/buttons/index.md
Hidden JavaScript code for the game, including canvas setup, game objects, and classes. This is part of the live example and is not meant to be visible in the page.
```javascript
const canvas = document.getElementById("game-canvas");
const ctx = canvas.getContext("2d");
let lastTimestamp = null;
let score = 0;
let lives = 3;
let showLifeLostText = false;
let playing = false;
const buttonControls = new AbortController();
const disappearingBricks = [];
const baseWallHitbox = {
left: -Infinity,
right: Infinity,
top: -Infinity,
bottom: Infinity,
};
const colliders = [
{ hitbox: { ...baseWallHitbox, right: 0 } },
{ hitbox: { ...baseWallHitbox, left: canvas.width } },
{ hitbox: { ...baseWallHitbox, bottom: 0 } },
];
class GameObject {
static assets = new Map();
url;
asset;
ctx;
size = { w: undefined, h: undefined };
pos = { x: 0, y: 0 };
origin = { x: 0.5, y: 0.5 };
constructor(url, ctx) {
this.url = url;
this.ctx = ctx;
}
async preload() {
if (!GameObject.assets.has(this.url)) {
const asset = new Image();
asset.src = this.url;
GameObject.assets.set(
this.url,
asset.decode().then(() => asset),
);
}
this.asset = await GameObject.assets.get(this.url);
if (this.size.w === undefined) {
this.size.w = this.asset.width;
this.size.h = this.asset.height;
}
}
get hitbox() {
const left = this.pos.x - this.size.w * this.origin.x;
const top = this.pos.y - this.size.h * this.origin.y;
return {
left,
right: left + this.size.w,
top,
bottom: top + this.size.h,
};
}
draw() {
const { left, top } = this.hitbox;
this.ctx.drawImage(this.asset, left, top);
}
onCollide() {}
}
class Ball extends GameObject {
size = { w: 20, h: 20 };
wobbleFrames = [0, 1, 0, 2, 0, 1, 0, 2, 0];
wobbleTime = null;
pos = { x: undefined, y: undefined };
vel = { x: 0, y: 0 };
move(dt) {
this.pos.x += this.vel.x * dt;
this.pos.y += this.vel.y * dt;
}
onCollide({ x, y }) {
if (x) {
this.vel.x = -this.vel.x;
}
if (y) {
this.vel.y = -this.vel.y;
}
}
playWobble() {
this.wobbleTime = 0;
}
updateAnimation(dt) {
if (this.wobbleTime === null) {
return;
}
this.wobbleTime += dt;
if (this.wobbleTime >= this.wobbleFrames.length * (1 / 24)) {
this.wobbleTime = null;
}
}
draw() {
const frame =
this.wobbleTime === null
? 0
: this.wobbleFrames[Math.floor(this.wobbleTime / (1 / 24))];
const { left, top } = this.hitbox;
this.ctx.drawImage(
this.asset,
frame * this.size.w,
0,
this.size.w,
this.size.h,
left,
top,
this.size.w,
this.size.h,
);
}
}
class Paddle extends GameObject {
origin = { x: 0.5, y: 1 };
constructor(url, ctx) {
super(url, ctx);
this.pos = { x: ctx.canvas.width / 2, y: ctx.canvas.height - 5 };
}
onCollide() {
ball.playWobble();
}
}
```
--------------------------------
### Create a starter HTML document
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/core/styling_basics/getting_started/index.md
Save this starter markup as index.html in your project directory. It provides sample headings, paragraphs, and list elements to style.
```html
Getting started with CSS
I am a level one heading
This is a paragraph of text. In the text is a
span element and also a
link.
This is the second paragraph. It contains an emphasized element.
Item one
Item two
Item three
```
--------------------------------
### Set up HTML, CSS, and logging utility for examples
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/prioritized_task_scheduling_api/index.md
Sets up the textarea element and helper logging function used throughout the examples to capture output.
```html
```
```css
#log {
min-height: 20px;
width: 95%;
}
```
```js
// hidden logger code - simplifies example
let log = document.getElementById("log");
function myLog(text) {
log.textContent += `${text}\n`;
}
```
--------------------------------
### scroll-snap-stop example CSS (hidden setup)
Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/reference/properties/scroll-snap-stop/index.md
Hidden CSS setup for the scroll-snap-stop example, defining layout, sizing, and coloration for the scroll containers and their children.
```css
/* setup */
body {
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
flex-flow: column nowrap;
font-family: monospace;
text-align: center;
}
div[class] {
font-size: 3rem;
display: flex;
overflow: auto;
flex: none;
}
.x {
width: 50%;
min-width: 15rem;
height: 6rem;
flex-flow: row nowrap;
}
.y {
width: 30%;
min-width: 12rem;
height: 12rem;
flex-flow: column nowrap;
}
div > div {
flex: none;
outline: 1px solid #333333;
}
.x > div {
width: 90%;
height: 100%;
}
.y > div {
width: 100%;
height: 80%;
}
/* coloration */
div > div:nth-child(even) {
background-color: #87ea87;
}
div > div:nth-child(odd) {
background-color: #87ccea;
}
```
--------------------------------
### Set up index.html and initialize Phaser.Game in script.js
Source: https://github.com/mdn/content/blob/main/files/en-us/games/tutorials/2d_breakout_game_phaser/initialize_the_framework/index.md
Create the base HTML structure in index.html to load Phaser and script.js, then define the initial ExampleScene and game configuration object in js/script.js.
```html
Breakout game
```
```js
class ExampleScene extends Phaser.Scene {
preload() {}
create() {}
update() {}
}
const config = {
type: Phaser.CANVAS,
width: 480,
height: 320,
scene: ExampleScene,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
backgroundColor: "#eeeeee",
};
const game = new Phaser.Game(config);
```
--------------------------------
### Handling the basic service worker install event
Source: https://github.com/mdn/content/blob/main/files/en-us/web/progressive_web_apps/tutorials/js13kgames/offline_service_workers/index.md
Attaches a basic event listener to the service worker's install event to log when the installation starts.
```js
self.addEventListener("install", (e) => {
console.log("[Service Worker] Install");
});
```
--------------------------------
### Create and start an HTTP server with http.createServer
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/node_server_without_framework/index.md
Initializes a server instance using http.createServer and starts listening on the specified PORT.
```javascript
http
.createServer((req, res) => {
/* handle http requests */
})
.listen(PORT);
console.log(`Server running at http://127.0.0.1:${PORT}/`);
```
--------------------------------
### Growing a box with arithmetic: JavaScript
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/cssnumericvalue/index.md
Gets the box and button, sets the maximum width as a CSSUnitValue, and uses computedStyleMap() to get the box's starting width and log it with its type(). On each click, reads the current width, adds 20px with add(), and uses min() to cap at maxWidth; because all values are in px, each method returns a CSSUnitValue that is set as the new width. The hidden logging code is not relevant to the example.
```js
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = `${logElement.innerText}${text}\n`;
logElement.scrollTop = logElement.scrollHeight;
}
```
```js
const growBox = document.getElementById("grow-box");
const growButton = document.getElementById("grow-button");
const maxWidth = CSS.px(300);
const startWidth = growBox.computedStyleMap().get("width");
log(`start: ${startWidth}, type: ${JSON.stringify(startWidth.type())}`);
```
```js
growButton.addEventListener("click", () => {
const width = growBox.computedStyleMap().get("width");
const newWidth = width.add(CSS.px(20)).min(maxWidth);
growBox.attributeStyleMap.set("width", newWidth);
log(`width: ${newWidth}`);
});
```
--------------------------------
### Example package.json configuration file
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/testing/automated_testing/index.md
Displays the initial package.json configuration file produced after completing the npm init questionnaire with default values.
```json
{
"name": "node-test",
"version": "1.0.0",
"description": "Test for npm projects",
"main": "index.js",
"scripts": {
"test": "test"
},
"author": "Chris Mills",
"license": "MIT"
}
```
--------------------------------
### Getting and setting HTMLOListElement start property
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/htmlolistelement/start/index.md
Demonstrates reading the default starting value of an ordered list element and updating it with a new starting value via JavaScript.
```html
Fee
Fi
Fo
Fum
```
```javascript
const olElement = document.querySelector("#order-list");
console.log(olElement.start); // Output: "1"
olElement.start = "11";
console.log(olElement.start); // Output: "11"
```
--------------------------------
### Syntax examples for image-set()
Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/reference/values/image/image-set/index.md
Demonstrates basic syntax options for image-set() using URLs, strings, gradients, resolution descriptors, and MIME types.
```css
/* Select image based on resolution */
image-set(
"image1.jpg" 1x,
"image2.jpg" 2x
);
image-set(
url("image1.jpg") 1x,
url("image2.jpg") 2x
);
/* Select gradient based on resolution */
image-set(
linear-gradient(blue, white) 1x,
linear-gradient(blue, green) 2x
);
/* Select image based on supported formats */
image-set(
url("image1.avif") type("image/avif"),
url("image2.jpg") type("image/jpeg")
);
```
--------------------------------
### Add a hidden install button
Source: https://github.com/mdn/content/blob/main/files/en-us/web/progressive_web_apps/how_to/trigger_install_prompt/index.md
Use a button element with the hidden attribute to provide an in-app installation trigger. The button starts hidden so it remains invisible on browsers that cannot install the app.
```html
```
--------------------------------
### Registering and using custom properties HTML and CSS setup
Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/guides/properties_and_values_api/registering_properties/index.md
Demonstrates an integrated example showing HTML markup, property registration via CSS @property and JavaScript CSS.registerProperty(), value assignment, and container styling.
```html
Item one
Item two
Item three
```
```css
@property --item-size {
syntax: "";
inherits: true;
initial-value: 40%;
}
```
```js
window.CSS.registerProperty({
name: "--item-color",
syntax: "",
inherits: false,
initialValue: "aqua",
});
```
```css
.container {
--item-size: 20%;
--item-color: orange;
}
.two {
--item-size: initial;
--item-color: inherit;
}
.three {
--item-size: 1000px;
--item-color: xyz;
}
```
```css
.item {
width: var(--item-size);
height: var(--item-size);
background-color: var(--item-color);
}
```
```css
.container {
display: flex;
height: 200px;
border: 1px dashed black;
}
```
--------------------------------
### Receiving a 200 OK response for a GET request
Source: https://github.com/mdn/content/blob/main/files/en-us/web/http/reference/status/200/index.md
Example of a successful GET response returning representation headers and an HTML message body.
```http
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 294510
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Fri, 21 Jun 2024 14:18:33 GMT
Etag: "3147526947"
Expires: Fri, 28 Jun 2024 14:18:33 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECAcc (nyd/D10E)
X-Cache: HIT
Content-Length: 1256
```
--------------------------------
### Animation.startTime
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/animation/starttime/index.md
Gets or sets a floating-point number representing the scheduled start time in milliseconds for the animation timeline, or null if no start time is set.
```APIDOC
## Animation.startTime
### Description
The `Animation.startTime` property of the `Animation` interface is a double-precision floating-point value indicating the scheduled time when an animation's playback should begin.
### Type
- `number | null`
### Value
A floating-point number representing the start time in milliseconds on the animation's timeline, or `null` if the start time is unresolved / no time is set.
### Usage
```javascript
// Read start time
const currentStartTime = animation.startTime;
// Set start time
animation.startTime = 1000;
// Sync start time with another animation
newAnimation.startTime = existingAnimation.startTime;
```
```
--------------------------------
### Initialize an npm project with npm init
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/testing/automated_testing/index.md
Navigate into the created directory and start the npm project initialization questionnaire. Accept the defaults during prompts to generate the project configuration.
```bash
cd node-test
npm init
```
--------------------------------
### Create project directory and navigate into it
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/express_nodejs/development_environment/index.md
Run these commands to create a new directory for the Express Local Library tutorial and change into it.
```bash
mkdir express-locallibrary-tutorial
cd express-locallibrary-tutorial
```
--------------------------------
### HTML video element for fullscreen example
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/fullscreen_api/guide/index.md
A video element with controls and two source files, used as the target for the requestFullscreen() example.
```html
```
--------------------------------
### Example requirements.txt contents
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/django/deployment/index.md
After installing all dependencies, requirements.txt should list at least these items; version numbers may differ. Delete any other dependencies not listed unless explicitly added for this application.
```plain
Django==6.1.1
dj-database-url==3.1.2
gunicorn==26.2.0
psycopg==3.3.6
psycopg-binary==3.3.6
whitenoise==6.12.0
python-dotenv==1.2.3
```
--------------------------------
### Example Django TestCase class with setUpTestData and setUp
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/django/testing/index.md
Add this class to the bottom of the test file. `setUpTestData()` runs once for class-level setup, while `setUp()` runs before every test method; the print statements show call order in the console.
```python
class YourTestClass(TestCase):
@classmethod
def setUpTestData(cls):
print("setUpTestData: Run once to set up non-modified data for all class methods.")
pass
def setUp(self):
print("setUp: Run once for every test method to set up clean data.")
pass
def test_false_is_false(self):
print("Method: test_false_is_false.")
self.assertFalse(False)
def test_false_is_true(self):
print("Method: test_false_is_true.")
self.assertTrue(False)
def test_one_plus_one_equals_two(self):
print("Method: test_one_plus_one_equals_two.")
self.assertEqual(1 + 1, 2)
```
--------------------------------
### Initialize a project with npm init or yarn init
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/client-side_tools/package_management/index.md
Walks through interactive prompts to describe the project and generates a package.json file. Choose either npm or Yarn and use it consistently within the project.
```bash
npm init
yarn init
```
--------------------------------
### Run the Beastify extension with web-ext run
Source: https://github.com/mdn/content/blob/main/files/en-us/mozilla/add-ons/webextensions/your_second_webextension/index.md
Automates the temporary installation step using the web-ext tool. Install web-ext first, then run these commands from the beastify directory.
```bash
cd beastify
web-ext run
```
--------------------------------
### HTML structure for scroll container example
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/element/scrollsnapchanging_event/index.md
A element with significant content that causes it to scroll. This is the starting point for the scroll snap example.
```html
```
--------------------------------
### Starting template for Strings 2 assessment
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/core/scripting/test_your_skills/strings/index.md
Initial setup providing the quote and substring variables along with DOM rendering logic for quoteLength and revisedQuote.
```javascript
const quote = "I do not like green eggs and ham. I do not like them, Sam-I-Am.";
const substring = "green eggs and ham";
// Don't edit the code above here!
// Add your code here
// Don't edit the code below here!
const section = document.querySelector("section");
section.innerHTML = " ";
const para1 = document.createElement("p");
para1.textContent = `The quote is ${quoteLength} characters long.`;
const para2 = document.createElement("p");
para2.textContent = revisedQuote;
section.appendChild(para1);
section.appendChild(para2);
```
--------------------------------
### Install project dependencies
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/express_nodejs/deployment/index.md
Run this command at the root of the project to fetch all dependencies before testing the site again.
```bash
npm install
```
--------------------------------
### Module directory structure for aggregation example
Source: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/guide/modules/index.md
Shows the file layout for the module-aggregation example, with a barrel module shapes.js and submodules in a shapes subdirectory.
```plain
modules/
canvas.js
shapes.js
shapes/
circle.js
square.js
triangle.js
```
--------------------------------
### BeforeInstallPromptEvent.prototype.prompt()
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/beforeinstallpromptevent/index.md
Displays a prompt asking the user if they want to install the web application. It returns a Promise resolving to an object that describes the user's decision.
```APIDOC
## BeforeInstallPromptEvent.prototype.prompt()
### Description
Shows a prompt asking the user if they want to install the app. This method returns a Promise that resolves to an object describing the user's choice when prompted.
### Syntax
```javascript
prompt()
```
### Parameters
None.
### Return Value
A `Promise` resolving to an object describing the user's choice when they were prompted to install the app (e.g., containing an `outcome` property).
### Example
```javascript
const result = await installPrompt.prompt();
console.log(`Install prompt was: ${result.outcome}`);
```
```
--------------------------------
### cross-fade() older implemented syntax examples
Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/reference/values/cross-fade/index.md
Examples of the older syntax with two images and a required percentage. The percentage is the opacity of the first image; the second image gets the remainder.
```css
cross-fade(url("white.png"), url("black.png"), 0%); /* fully black */
cross-fade(url("white.png"), url("black.png"), 25%); /* 25% white, 75% black */
cross-fade(url("white.png"), url("black.png"), 50%); /* 50% white, 50% black */
cross-fade(url("white.png"), url("black.png"), 75%); /* 75% white, 25% black */
cross-fade(url("white.png"), url("black.png"), 100%); /* fully white */
```
--------------------------------
### Record start and end timestamps with queryCounterEXT()
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/ext_disjoint_timer_query/querycounterext/index.md
Get the EXT_disjoint_timer_query extension, create start and end query objects, and record the current time into each with ext.TIMESTAMP_EXT.
```js
const ext = gl.getExtension("EXT_disjoint_timer_query");
const startQuery = ext.createQueryEXT();
const endQuery = ext.createQueryEXT();
ext.queryCounterEXT(startQuery, ext.TIMESTAMP_EXT);
// …
ext.queryCounterEXT(endQuery, ext.TIMESTAMP_EXT);
```
--------------------------------
### Create the catalog app with manage.py startapp
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/django/skeleton_website/index.md
Run from the same folder as the project's manage.py to create the catalog application inside the locallibrary project. Use the Windows variant with py on Windows; the rest of the tutorial uses the Linux/macOS python3 syntax.
```bash
python3 manage.py startapp catalog
```
--------------------------------
### Set up starter HTML and CSS for the color scheme search application
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/core/styling_basics/home_color_scheme_search/index.md
Provides the starter HTML structure and baseline CSS styling for the color scheme search app mockup. Includes a form with input fields, a results table with image placeholders, pagination controls, and initial flex layout styles.
```html
Home color search
Search results
Sample colors and color schemes
Color
Raw color
Tags
Sample color scheme
Pink
rgb(255 192 203)
pink, pale, light
Baker-Miller pink
rgb(255 145 175)
pink, pale, bright
Hotpink
rgb(255 105 180)
pink, bright, vivid
Fuchsia
rgb(255 0 255)
pink, medium, bright
Showing page 1 of 20
```
```css
* {
box-sizing: border-box;
}
html {
font-family: "Helvetica", "Arial", sans-serif;
}
body {
margin: 0 10px;
}
hr {
margin: 3em 0;
}
h2 {
margin-top: 0;
}
/* Prev/next control layout */
.controls {
display: flex;
padding: 10px 0;
justify-content: space-between;
align-items: center;
}
/* Form and button styling */
form div {
display: flex;
align-items: center;
gap: 2em;
margin-bottom: 1em;
}
label {
text-align: right;
flex: 1;
}
input {
flex: 3;
}
/* Table styling */
table img {
width: 100%;
height: 150px;
}
```
--------------------------------
### browser.runtime.onStartup
Source: https://github.com/mdn/content/blob/main/files/en-us/mozilla/add-ons/webextensions/api/runtime/onstartup/index.md
Fired when a profile that has this extension installed first starts up. This event is not fired when a private browsing (incognito) profile is started, even if the extension is operating in 'split' incognito mode.
```APIDOC
## browser.runtime.onStartup
### Description
Fired when a profile that has this extension installed first starts up. This event is not fired when a private browsing (incognito) profile is started, even if this extension is operating in 'split' incognito mode.
### Syntax
```javascript
browser.runtime.onStartup.addListener(listener)
browser.runtime.onStartup.removeListener(listener)
browser.runtime.onStartup.hasListener(listener)
```
### Event Functions
- `addListener(listener)`: Adds a listener to the event.
- `removeListener(listener)`: Stop listening to the calling event. The `listener` argument is the listener to remove.
- `hasListener(listener)`: Checks whether a `listener` is registered for the calling event. Returns `true` if listening, `false` otherwise.
### Parameters
- **listener** (`function`) - Required. The function called when this event occurs.
### Example
```javascript
function handleStartup() {
browser.tabs.create({
url: "https://giphy.com/explore/cat",
});
}
browser.runtime.onStartup.addListener(handleStartup);
```
```
--------------------------------
### Create a skeleton site with django-admin startproject
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/extensions/server-side/django/development_environment/index.md
Creates a new skeleton site named mytestsite and navigates into it, where manage.py is located.
```bash
django-admin startproject mytestsite
cd mytestsite
```
--------------------------------
### Hidden CSS styling for fullscreen keyboard locking example
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/fullscreen_api/guide/index.md
Hidden styles applied to the example page, including the video backdrop and kbd styling.
```css
body {
font-family:
"Benton Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
margin: 2em;
}
video::backdrop {
background-color: #444488;
}
button {
display: block;
}
kbd {
border: 2px solid #cdcdcd;
border-radius: 3px;
box-shadow: inset 0 -1px 0 0 #cdcdcd;
font-size: 0.825rem;
padding: 0.25rem;
}
```
--------------------------------
### Check and install language packs with SpeechRecognition.available() and install()
Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/web_speech_api/using_the_web_speech_api/index.md
Use this click handler to check whether the en-US language pack is available for on-device speech recognition and install it if needed. If the pack is unavailable, recognition cannot start; if downloadable or downloading, install() is called. The available() and install() methods are controlled by the on-device-speech-recognition Permissions-Policy directive.
```javascript
startBtn.addEventListener("click", () => {
// check availability of target language
SpeechRecognition.available({ langs: ["en-US"], processLocally: true }).then(
(result) => {
if (result === "unavailable") {
diagnostic.textContent = `en-US is not available to download at this time. Sorry!`;
} else if (result === "available") {
recognition.start();
console.log("Ready to receive a color command.");
} else {
diagnostic.textContent = `en-US language pack is downloading...`;
SpeechRecognition.install({
langs: ["en-US"],
processLocally: true,
}).then((result) => {
if (result) {
diagnostic.textContent = `en-US language pack downloaded. Start recognition again.`;
} else {
diagnostic.textContent = `en-US language pack failed to download. Try again later.`;
}
});
}
},
);
});
```
--------------------------------
### Handle extension installation with runtime.onInstalled
Source: https://github.com/mdn/content/blob/main/files/en-us/mozilla/add-ons/webextensions/api/runtime/oninstalled/index.md
Registers a listener for the onInstalled event to log the install reason and open a specified URL in a new tab.
```javascript
function handleInstalled(details) {
console.log(details.reason);
browser.tabs.create({
url: "https://example.com",
});
}
browser.runtime.onInstalled.addListener(handleInstalled);
```
--------------------------------
### Create a starter HTML template for testing JavaScript objects
Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/core/scripting/object_basics/index.md
Sets up a minimal HTML document containing a