The task on this page is a short sustained attention test in the continuous performance / go-no-go family. A stream of single digits appears on the screen, one every 1.5 seconds, and the participant has a single rule: press the space bar when the digit is a 5, and do nothing for any other digit. That is all. The difficulty is not the rule but keeping it active, trial after trial, when most of the stream requires no action at all.
Tasks of this kind do not produce a single "attention span" number measured in seconds. Instead they yield several complementary measures:
In longer versions, researchers also look at how these measures change from the first block to the last (the "vigilance decrement").
The closest ancestor is the Continuous Performance Test (CPT) introduced by Rosvold, Mirsky, Sarason, Bransome and Beck (1956), originally developed to study attention deficits in patients with brain damage. In the classic "X" version participants watched a sequence of letters and responded only to the letter X; in the "AX" version they responded to X only when it followed an A. CPT variants remain in clinical use today, particularly in ADHD assessment.
A second, very influential relative is the Sustained Attention to Response Task (SART) of Robertson, Manly, Andrade, Baddeley and Yiend (1997). The SART inverts the rule: digits 1 to 9 are presented and participants respond to every digit except the 3, which must be withheld. Because responding becomes the habit, the rare no-go trials are sensitive to momentary lapses, and SART commission errors have been linked to self-reported absent-mindedness and to mind-wandering.
The demo below is closer to the CPT logic (respond to the rare target) while borrowing the digit stream from the SART. It is a teaching example, not a validated clinical instrument.
You may have read that the average human attention span has dropped to eight seconds, "shorter than a goldfish". That figure comes from a 2015 marketing report, not from a peer-reviewed measurement, and it does not correspond to anything that tasks like the CPT or SART measure. Attention is task-dependent: the same person who loses focus within a minute on a monotonous vigilance task can concentrate for hours on a film or a video game. Rather than a fixed "span", research measures how performance on a specific task degrades under specific conditions, which is exactly what omission rates, commission rates and RT variability capture.
The demo below shows 25 digits. Press the space bar only when you see a 5. At the end you will see the percentage of trials you got right.
The embedded demo runs on an earlier version of jsPsych. The code below is the equivalent implementation written for jsPsych 8 (it also runs on jsPsych 7). It generates 25 random digits between 1 and 9, shows each one for 1000 ms followed by a 500 ms blank gap, marks each trial as correct or incorrect, and reports accuracy at the end. Note that accuracy is calculated only over trials tagged task: "attention", so instruction and debrief screens are not counted.
const jsPsych = initJsPsych({
on_finish: () => {
jsPsych.data.displayData();
}
});
const timeline = [];
// Instructions
const instructions = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "<p>You will see a series of numbers.</p>" +
"<p>Press the <strong>space bar</strong> only when you see the number <strong>5</strong>.</p>" +
"<p>Press any key to begin.</p>",
post_trial_gap: 500
};
timeline.push(instructions);
// Build 25 random digits between 1 and 9
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const stimuli = [];
for (let i = 0; i < 25; i++) {
const number = jsPsych.randomization.sampleWithoutReplacement(numbers, 1)[0];
stimuli.push({ stimulus: number.toString(), is_target: number === 5 });
}
// One digit: 1000 ms on screen, then a 500 ms blank gap
const attention_trial = {
type: jsPsychHtmlKeyboardResponse,
stimulus: () => "<span style="font-size: 40px">" + jsPsych.evaluateTimelineVariable("stimulus") + "</span>",
choices: [" "],
trial_duration: 1000,
response_ends_trial: false,
post_trial_gap: 500,
data: {
task: "attention",
digit: jsPsych.timelineVariable("stimulus"),
is_target: jsPsych.timelineVariable("is_target")
},
on_finish: (data) => {
const pressed = jsPsych.pluginAPI.compareKeys(data.response, " ");
data.correct = data.is_target ? pressed : data.response === null;
}
};
timeline.push({
timeline: [attention_trial],
timeline_variables: stimuli
});
// Debrief: accuracy over the attention trials only
const debrief = {
type: jsPsychHtmlKeyboardResponse,
stimulus: () => {
const trials = jsPsych.data.get().filter({ task: "attention" });
const correct = trials.filter({ correct: true }).count();
const accuracy = Math.round(correct / trials.count() * 100);
const omissions = trials.filter({ is_target: true, correct: false }).count();
const commissions = trials.filter({ is_target: false, correct: false }).count();
return "<p>You responded correctly on " + accuracy + "% of the trials.</p>" +
"<p>Missed targets: " + omissions + ". False alarms: " + commissions + ".</p>" +
"<p>Press any key to complete the experiment.</p>";
}
};
timeline.push(debrief);
jsPsych.run(timeline);
Setting response_ends_trial: false keeps every digit on screen for the full 1000 ms, so the pace of the stream is identical regardless of whether the participant responds. Because of the random sampling, the number of targets varies from run to run; for a real study you would typically fix the target rate (for example, 5 targets in 25 trials) and shuffle the order.
To run this task with real participants, paste the code above into the Cognition editor. The editor shows a live preview and an error console, so you can check the timing and the debrief screen before sharing anything. Once saved, the task gets its own link of the form https://<token>.cognition.run.
Every trial is sent to the server as it finishes, so a participant who closes the tab halfway through still leaves usable data, and a service worker stores trials locally and resends them if the connection drops. Data can be downloaded as CSV or JSON, with the task, digit, is_target, response, rt and correct columns ready for computing omission rates, commission rates and RT variability. If you recruit through Prolific or SONA, the ID in the URL query string is attached as a column to every trial; see our guide on integrating jsPsych with Prolific, SONA and MTurk.
The Free plan covers 4 tasks with up to 60 participants each, which is enough for a pilot. Create a free account to try it, or browse the documentation for details on consent forms, single-use links and between-subjects conditions.
The demo above was created using the jsPsych library—a powerful tool for building behavioral experiments in a web browser. This library provides a flexible framework for designing a wide variety of cognitive tests, making it a favorite among researchers and educators.
What's even more exciting is that this demo is hosted using Cognition. Cognition offers a seamless platform to create, run, and manage online experiments, relieving users of the complexities related to web hosting, data storage, and security.
Inspired by what you've seen? Ready to dive into the world of online experiments? With Cognition, you can run and share your experiments online effortlessly. Whether you're a seasoned researcher or just curious about cognitive tests, Cognition is here to simplify the journey.