explaingit

davatron5000/fitvids.js

4,717HTMLAudience · developerComplexity · 1/5Setup · easy

TLDR

A jQuery plugin that makes embedded YouTube and Vimeo videos resize proportionally at any screen width, solving the fixed-size iframe problem in responsive web designs with a single function call.

Mindmap

mindmap
  root((fitvids))
    What it does
      Resize video iframes
      Responsive scaling
      CSS wrapper
    Supported players
      YouTube
      Vimeo
      Custom selectors
    Options
      Ignore selector
      Custom player
    Use cases
      Responsive blogs
      CMS sites
      Video landing pages
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Make embedded YouTube or Vimeo iframes scale proportionally on a responsive website without writing custom CSS.

USE CASE 2

Apply FitVids to a blog or CMS so all video embeds resize correctly on mobile without editing each embed code individually.

USE CASE 3

Extend FitVids with a custom selector to support a non-standard video provider that outputs fixed-size iframes.

Tech stack

JavaScriptjQueryCSS

Getting it running

Difficulty · easy Time to first run · 5min

Requires jQuery 1.7 or later, the plugin itself is just one script include away.

In plain English

FitVids.js is a small jQuery plugin that solves a common layout problem in responsive web design: embedded videos that refuse to resize properly when the browser window changes width. YouTube, Vimeo, and a handful of other players produce fixed-size iframes by default, which break on narrow screens. FitVids automatically wraps each video in a container that scales proportionally, so the video fills its column at any screen size. To use it, you include jQuery (version 1.7 or later) and the FitVids script in your page, then call .fitVids() on the element that contains your videos. From that point on, the sizing is handled entirely by percentage-based CSS. The script sets up the wrapper once, no ongoing JavaScript is needed after the initial call. The plugin ships with built-in support for YouTube and Vimeo. Blip.tv, Viddler, and Kickstarter were supported at some point but may be deprecated. If you use a video provider that is not on the default list, you can pass a custom CSS selector to tell FitVids which iframes to include. This is also the recommended way to test whether a given player works well with the scaling approach. There is also an option to exclude specific videos or containers. Adding a fitvidsignore class to an element tells the plugin to skip it, or you can pass a list of selectors via the ignore option if you prefer not to modify your markup. One known limitation: Vimeo's Autoplay API does not work with FitVids in Internet Explorer 11. For videos that need to autoplay in that browser, you have to wrap them manually. The library is a focused solution to a narrow problem that was widespread during the rise of responsive design.

Copy-paste prompts

Prompt 1
Show me the minimal setup to add FitVids.js so all YouTube and Vimeo embeds inside a div with class .content resize responsively.
Prompt 2
I have YouTube embeds and a custom player from a non-standard provider. How do I configure FitVids to handle both using customSelector?
Prompt 3
What does FitVids.js actually change in the DOM? Walk me through the wrapper it creates and the CSS it applies to scale the video.
Open on GitHub → Explain another repo

← davatron5000 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.