### 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:

If you are interested, then don't hesitate to get in touch; we'd love to hear from you:

  1. Call or Email us for more information.
  2. Ask for a brochure, which includes a signup form.
  3. Book a visit!
``` ```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.

``` -------------------------------- ### 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
  1. Fee
  2. Fi
  3. Fo
  4. 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 Image of living room in a pink color scheme
Baker-Miller pink rgb(255 145 175) pink, pale, bright Image of living room in a Baker-Miller pink color scheme
Hotpink rgb(255 105 180) pink, bright, vivid Image of living room in a hotpink color scheme
Fuchsia rgb(255 0 255) pink, medium, bright Image of living room in a fuchsia color scheme

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 ``` -------------------------------- ### Pad a string with padStart() interactive example Source: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/reference/global_objects/string/padstart/index.md Pads the start of a string to reach a target length. The second example masks all but the last four digits of a number using '*' padding. ```js const str = "5"; console.log(str.padStart(2, "0")); // Expected output: "05" const fullNumber = "2034399002125581"; const last4Digits = fullNumber.slice(-4); const maskedNumber = last4Digits.padStart(fullNumber.length, "*"); console.log(maskedNumber); // Expected output: "************5581" ``` -------------------------------- ### Hidden HTML controls for column-rule-inset-junction example Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/reference/properties/column-rule-inset-junction/index.md Provides range inputs and outputs to adjust the start and end inset values dynamically. Hidden from the rendered example. ```html

16px

0px

``` -------------------------------- ### Complete Breakout physics setup live sample Source: https://github.com/mdn/content/blob/main/files/en-us/games/tutorials/2d_breakout_game_phaser/physics/index.md Demonstrates the complete implementation with HTML, CSS, and JavaScript integrating Arcade Physics and moving the ball sprite. ```html ``` ```css * { padding: 0; margin: 0; } ``` ```javascript class ExampleScene extends Phaser.Scene { ball; preload() { this.load.setBaseURL( "https://mdn.github.io/shared-assets/images/examples/2D_breakout_game_Phaser", ); this.load.image("ball", "ball.png"); } create() { this.ball = this.add.sprite(50, 50, "ball"); this.physics.add.existing(this.ball); this.ball.body.setVelocity(150, 150); } update() {} } const config = { type: Phaser.CANVAS, width: 480, height: 320, scene: ExampleScene, scale: { mode: Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH, }, backgroundColor: "#eeeeee", physics: { default: "arcade", }, }; const game = new Phaser.Game(config); ``` -------------------------------- ### Set up HTML structure for static positioning example Source: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/core/css_layout/positioning/index.md Provides the complete HTML sample showing block and inline elements with a targeted positioned class. ```html

Static positioning

I am a basic block level element. My adjacent block level elements sit on new lines below me.

By default we span 100% of the width of our parent element, and our are as tall as our child content. Our total width and height is our content + padding + border width/height.

We are separated by our margins. Because of margin collapsing, we are separated by the width of one of our margins, not both.

inline elements like this one and this one sit on the same line as one another, and adjacent text nodes, if there is space on the same line. Overflowing inline elements wrap onto a new line if possible — like this one containing text, or just go on to a new line if not, much like this image will do: a wide but short section of a photo of several fabrics

``` -------------------------------- ### Hidden CSS for exit-crossing percentage example Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/guides/scroll-driven_animations/timeline_insets/index.md Supporting styles for the exit-crossing percentage example: removes the article background image and aligns the animated element to the start. ```css article { background-image: none; } body .animated_element { align-self: start; } ``` -------------------------------- ### Syntax examples for `anchor-size()` Source: https://github.com/mdn/content/blob/main/files/en-us/web/css/reference/values/anchor-size/index.md Demonstrates various syntax configurations for `anchor-size()`, including parameterless defaults, dimension keywords, named anchors, fallback lengths, inset positioning, and margin calculations. ```css /* without parameters */ anchor-size() /* anchor size parameter */ anchor-size(width); anchor-size(block); anchor-size(self-inline); /* anchor-name and anchor-side */ width: anchor-size(--my-anchor width); block-size: anchor-size(--my-anchor block); /* sizing relative to named anchor's side with fallback */ width: anchor-size(--my-anchor width, 50%); block-size: anchor-size(--my-anchor block, 200px); /* positioning relative to anchor side */ left: anchor-size(width); inset-inline-end: anchor-size(--my-anchor height, 100px); /* setting margin relative to anchor side */ margin-left: calc(anchor-size(width) / 4); margin-block-start: anchor-size(--my-anchor self-block, 20px); ``` -------------------------------- ### VTTCue.prototype.lineAlign Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/vttcue/linealign/index.md Gets or sets the line alignment of the VTTCue object. It can be set to 'start', 'center', or 'end'. ```APIDOC ## VTTCue: lineAlign Property ### Description The `lineAlign` property of the `VTTCue` interface represents the alignment of this VTT cue. ### Syntax ```js // Getting the lineAlign value const alignment = vttCue.lineAlign; // Setting the lineAlign value vttCue.lineAlign = value; ``` ### Value A string representing cue line alignment. Allowed values include: - `"start"`: Start alignment. - `"center"`: Center alignment. - `"end"`: End alignment. ### Example ```js let video = document.querySelector("video"); let track = video.addTextTrack("captions", "Captions", "en"); track.mode = "showing"; let cue = new VTTCue(0, 0.9, "Hildy!"); cue.lineAlign = "center"; console.log(cue.lineAlign); track.addCue(cue); ``` ``` -------------------------------- ### Syntax for MessagePort start() Source: https://github.com/mdn/content/blob/main/files/en-us/web/api/messageport/start/index.md Syntax for calling the start() method on a MessagePort instance. ```javascript start() ```