D.C. Mayor Muriel E. Bowser stands in the back, right, with students at the Anacostia Neighborhood Library, where President Obama spoke about an initiative to expand poor children’s access to books. (Mandel Ngan/AFP/Getty Images)

President Obama traveled five miles from home Thursday and did something he had never done in more than six years in the White House: make an announcement with the mayor of the District of Columbia.

At the Anacostia Neighborhood Library, Obama unveiled initiatives to promote reading among young people, including those in low-income households.

Obama announced that nine major publishing houses will donate digital access to about 10,000 of their popular titles, worth about $250 million, to low-income students. Also, the District and about 30 other towns and cities said they would introduce or press ahead with plans to put library cards in the hands of every student — giving lower-income students access to digital books in libraries even when they lack Internet access at home.

“For a lot of people, if they live in a home where they don’t have a lot of books, books can be expensive. Your parents may not be able to afford to buy a whole lot of books,” said Obama, sitting on a stool and facing 40 wide-eyed middle-school students. “But if we are able to set up . . . a way in which people can pull all of these books down through the Internet, suddenly that can even things out between poor kids and rich kids — everybody has got the ability to learn.”

D.C. Mayor Muriel E. Bowser (D) and Kaya Henderson, the D.C. Public Schools chancellor, sat behind the students at the president’s talk.

Later Thursday, Bow­ser announced that the city would be among the first to embrace Obama’s plan. Next school year, every student ID card in the District will double as a library card, the officials said, giving children easier access to libraries and the growing online catalogue of digital books they can access at home.

In one of the poorest pockets of the nation’s capital, where last year the elementary school closest to the library recorded a 34 percent proficiency rate in reading and the closest high school graduated 39 percent of its students, the setting and a beaming mayor in the background offered a perfect, if rarely used, backdrop for Obama.

Aside from a hot dog in 2009 with then-Mayor Adrian M. Fenty (D) and a White House luncheon with Mayor-elect Vincent C. Gray (D) in 2010, Obama has rarely interacted with city leaders during his time in office.

More often, he has traveled to suburbs in Maryland or Virginia — or to cities farther afield — to illustrate the need for greater investments to help the poor and close the country’s growing economic divide.

The president’s arm’s length from the District coincided with a cloud of scandal that hung over the mayor’s office as a federal investigation into campaign spending on behalf of Gray ground along.

Last fall, however, the president’s interest in the District appeared to warm: He endorsed Bowser a month before the general election, calling her a “champion for working and middle-class families and a passionate proponent of Washington, D.C.”

“As we continue our efforts to move our country’s economy forward, I know I’ll be able to count on Muriel to expand opportunity for all,” Obama said in the October statement.

Outside the library Thursday, a crowd had gathered along Good Hope Road to watch the president’s motorcade stop in a part of town he has rarely visited.

The president also said that the New York Public Library would help take the lead in developing an e-reader app that would provide greater access to classics in the public domain for students age 4 to 18 from low-income families. Nonprofit groups will help that effort.

“How many people here have a smartphone?” Obama asked the students. More than half of the middle-school students’ hands shot up. “You’re texting all day and looking at Vines and Instagrams. You’re looking at, like, Grumpy Cat, or some video of your favorite singer,” he said. “We want to make sure that becomes a tool for not just entertainment, not just for talking to your friends, but for learning.”

Jeffrey Zients, chairman of the National Economic Council, said the donations by “an honor roll of major publishers” would provide “opportunity for kids to develop a love of learning.” Macmillan will provide unlimited access to about 2,500 titles for children in kindergarten through 12th grade. Simon & Schuster will provide access to its entire e-catalogue of books for children age 4 to 14 — about 3,000 titles.

He cited statistics that there are 13 books per child in neighborhoods that are middle-income but only one for every 300 children in poor neighborhoods.

Zients said the initiatives would build on Obama’s ConnectED initiative, which works to make sure that 99 percent of students are connected to high-speed broadband in their classrooms and libraries.

Asked by a 12-year-old what kind of technology he had in school growing up, Obama replied: “Pencils, and we had pens, and we some colored markers, and erasers, scissors. We had rulers, staplers — no, I’m serious,” Obama said to growing laughter. “You guys don’t even know how good you’ve got it.”